Skip to content
Permalink
Browse files

Merge pull request #131 from rupprecht/asan-fix

ParseBuffer: Skip substring search in skipToChars when the length is …
  • Loading branch information
sgodin committed Nov 2, 2019
2 parents 756dd98 + 4e5033b commit 1248ca9cf04daf5bd8e1aa1e7c00f0ee10dfe6a4
Showing with 12 additions and 1 deletion.
  1. +5 −1 rutil/ParseBuffer.cxx
  2. +7 −0 rutil/test/testParseBuffer.cxx
@@ -247,7 +247,9 @@ ParseBuffer::skipToChars(const char* cs)

const char* rpos;
const char* cpos;
while (mPosition < mEnd)
// Checking mPosition >= mEnd - l is unnecessary because there won't be
// enough bytes left to find [cs].
while (mPosition < mEnd - l)
{
rpos = mPosition;
cpos = cs;
@@ -262,6 +264,8 @@ ParseBuffer::skipToChars(const char* cs)
return CurrentPosition(*this);
skip: ;
}
// Advance to the end since we didn't find a match.
mPosition = mEnd;
return CurrentPosition(*this);
}

@@ -257,6 +257,13 @@ main(int argc, char** argv)
pb.assertEof();
}

{
char buf[] = {'a', 'x', 'y'}; // Intentionally not NUL terminated.
ParseBuffer pb(buf, sizeof(buf)); // Note: sizeof instead of strlen.

pb.skipToChars("xyzabc123");
}

{
char buf[] = "Here is a \t buffer with some stuff.";
ParseBuffer pb(buf, strlen(buf));

0 comments on commit 1248ca9

Please sign in to comment.
You can’t perform that action at this time.