Skip to content

Commit fc1fb6a

Browse files
committed
Fix potential buffer overread in CountNewlines in Scan.cpp
cch parameter is ignored if psz is not null-terminated and psz[cch-1] == '\r' and psz[cch] == '\n'.
1 parent c9a6482 commit fc1fb6a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/Parser/Scan.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ int CountNewlines(LPCOLESTR psz, int cch)
1919
switch (*psz++)
2020
{
2121
case _u('\xD'):
22-
if (*psz == _u('\xA'))
22+
if (cch != 0 && *psz == _u('\xA'))
2323
{
2424
++psz;
25-
if (0 == cch--)
26-
break;
25+
--cch;
2726
}
2827
// fall-through
2928
case _u('\xA'):

0 commit comments

Comments
 (0)