Fix unchecked buffer size issues in l_script.c and l_precomp.c

Found by Coverity.
This commit is contained in:
Zack Middleton 2014-05-25 17:02:33 -05:00
parent 078d004dc2
commit eea9fbdb61
2 changed files with 16 additions and 9 deletions

View file

@ -995,14 +995,14 @@ int PC_Directive_include(source_t *source)
script = LoadScriptFile(token.string);
if (!script)
{
strcpy(path, source->includepath);
strcat(path, token.string);
Q_strncpyz(path, source->includepath, sizeof(path));
Q_strcat(path, sizeof(path), token.string);
script = LoadScriptFile(path);
} //end if
} //end if
else if (token.type == TT_PUNCTUATION && *token.string == '<')
{
strcpy(path, source->includepath);
Q_strncpyz(path, source->includepath, sizeof(path));
while(PC_ReadSourceToken(source, &token))
{
if (token.linescrossed > 0)
@ -1011,7 +1011,7 @@ int PC_Directive_include(source_t *source)
break;
} //end if
if (token.type == TT_PUNCTUATION && *token.string == '>') break;
strncat(path, token.string, MAX_PATH - 1);
Q_strcat(path, sizeof(path), token.string);
} //end while
if (*token.string != '>')
{
@ -2831,6 +2831,7 @@ int PC_ExpectTokenType(source_t *source, int type, int subtype, token_t *token)
{
if ((token->subtype & subtype) != subtype)
{
strcpy(str, "");
if (subtype & TT_DECIMAL) strcpy(str, "decimal");
if (subtype & TT_HEX) strcpy(str, "hex");
if (subtype & TT_OCTAL) strcpy(str, "octal");
@ -2954,10 +2955,14 @@ void PC_UnreadToken(source_t *source, token_t *token)
//============================================================================
void PC_SetIncludePath(source_t *source, char *path)
{
strncpy(source->includepath, path, MAX_PATH);
size_t len;
Q_strncpyz(source->includepath, path, MAX_PATH-1);
len = strlen(source->includepath);
//add trailing path seperator
if (source->includepath[strlen(source->includepath)-1] != '\\' &&
source->includepath[strlen(source->includepath)-1] != '/')
if (len > 0 && source->includepath[len-1] != '\\' &&
source->includepath[len-1] != '/')
{
strcat(source->includepath, PATHSEPERATOR_STR);
} //end if