some more boundary checking

This commit is contained in:
svdijk 2013-05-08 20:16:23 +02:00
parent 3c62c2be5a
commit cd54f56b36
4 changed files with 6 additions and 6 deletions

View File

@ -90,7 +90,7 @@ LoadJPG(char *origname, byte **pic, int *width, int *height)
/* Add the extension */
len = strlen(filename);
if (strcmp(filename + len - 4, ".jpg"))
if (len >= 4 && strcmp(filename + len - 4, ".jpg"))
{
strncat(filename, ".jpg", sizeof(filename) - 1 - len);
}

View File

@ -42,8 +42,8 @@ LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height)
filename[sizeof(filename) - 1] = '\0';
/* Add the extension */
filelen = strlen(origname);
if (strcmp(filename + filelen - 4, ".pcx"))
filelen = strlen(filename);
if (filelen >= 4 && strcmp(filename + filelen - 4, ".pcx"))
{
strncat(filename, ".pcx", sizeof(filename) - 1 - filelen);
}

View File

@ -54,8 +54,8 @@ LoadTGA(char *origname, byte **pic, int *width, int *height)
name[sizeof(name) - 1] = '\0';
/* Add the extension */
len = strlen(origname);
if (strcmp(name + len - 4, ".tga"))
len = strlen(name);
if (len >= 4 && strcmp(name + len - 4, ".tga"))
{
strncat(name, ".tga", sizeof(name) - 1 - len);
}

View File

@ -40,7 +40,7 @@ LoadWal(char *origname)
/* Add the extension */
len = strlen(name);
if (strcmp(name + len - 4, ".wal"))
if (len >= 4 && strcmp(name + len - 4, ".wal"))
{
strncat(name, ".wal", sizeof(name) - 1 - len);
}