G_SaveDemo: fix oob reads/writes for replay names
demo.titlename has a size of 65! not 128! also handles memory failure and checks bounds for the remaining lenght in the demo slug
This commit is contained in:
1 parent
3ddb525d7f
commit
2eca62db79
1 file changed
+14
-4
+14
-4
@@ -3569,7 +3569,8 @@ void G_SaveDemo(void)
|
||||
size_t i, strindex = 0;
|
||||
boolean dash = true;
|
||||
|
||||
for (i = 0; demo.titlename[i] && i < 127; i++)
|
||||
//for (i = 0; demo.titlename[i] && i < 127; i++) ?????
|
||||
for (i = 0; i < 64 && demo.titlename[i]; i++)
|
||||
{
|
||||
if ((demo.titlename[i] >= 'a' && demo.titlename[i] <= 'z') ||
|
||||
(demo.titlename[i] >= '0' && demo.titlename[i] <= '9'))
|
||||
@@ -3601,9 +3602,18 @@ void G_SaveDemo(void)
|
||||
if (demo_slug[0] != '\0')
|
||||
{
|
||||
// Slug is valid, write the chosen filename.
|
||||
writepoint = strstr(demoname, "-") + 1;
|
||||
demo_slug[128 - (writepoint - demoname) - 4] = 0;
|
||||
sprintf(writepoint, "%s.lmp", demo_slug);
|
||||
writepoint = strstr(demoname, "-");
|
||||
if (!writepoint)
|
||||
return;
|
||||
|
||||
writepoint++;
|
||||
|
||||
size_t flen = 128 - (writepoint - demoname) - 4;
|
||||
if (flen > 0 && flen < 128)
|
||||
{
|
||||
demo_slug[flen] = '\0';
|
||||
sprintf(writepoint, "%s.lmp", demo_slug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user