Skip to content

Commit

Permalink
qmanifest: avoid out of bounds access in append_list macro
Browse files Browse the repository at this point in the history
Empty strings, or those being just whitespace were not handled
correctly.  Thanks bstaletic in PR #19 for pointing this out.  Avoid
running under the original string pointer and skip any checks for
strings that are too short to match anything in particular.  This sweeps
an edgecase of just a single whitespace char under the carpet -- which
is just about fine, for it needs not to be handled for any legitimate
case.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
  • Loading branch information
grobian committed Mar 29, 2024
1 parent 26fe1cf commit cc4de0d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions qmanifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,13 +1421,15 @@ verify_manifest(
#define append_list(STR) \
if (strncmp(STR, "TIMESTAMP ", 10) != 0 || strncmp(STR, "DIST ", 5) != 0) {\
char *endp = STR + strlen(STR) - 1;\
while (isspace(*endp))\
while (endp > STR && isspace(*endp))\
*endp-- = '\0';\
if (elemslen == elemssize) {\
elemssize += LISTSZ;\
elems = xrealloc(elems, elemssize * sizeof(elems[0]));\
}\
if (strncmp(STR, "IGNORE ", 7) == 0) {\
if (endp - STR < 4) {\
/* avoid doing comparisons, none will match */\
} else if (strncmp(STR, "IGNORE ", 7) == 0) {\
STR[5] = 'I';\
elems[elemslen] = xstrdup(STR + 5);\
elemslen++;\
Expand Down

0 comments on commit cc4de0d

Please sign in to comment.