Skip to content

Commit

Permalink
Fix potential buffer overflow.
Browse files Browse the repository at this point in the history
There was a case where we could read past the end of the token buffer if a
 comment token said it was larger than it really was.

--HG--
branch : trunk
  • Loading branch information
icculus committed Jun 25, 2008
1 parent b58fd47 commit 0312e92
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mojoshader.c
Expand Up @@ -6939,9 +6939,14 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
// reset for every token, and consider an error if it ever overflows!
ctx->scratchidx = 0;

ctx->tokens += rc;
ctx->tokencount -= rc;
rc = parse_token(ctx);
if ( ((uint32) rc) > ctx->tokencount )
fail(ctx, "Corrupted or truncated shader");
else
{
ctx->tokens += rc;
ctx->tokencount -= rc;
rc = parse_token(ctx);
} // else
} // while

if (!isfail(ctx))
Expand Down

0 comments on commit 0312e92

Please sign in to comment.