Skip to content

Commit

Permalink
Avoid incrementing a pointer past the end
Browse files Browse the repository at this point in the history
The ‘end’ parameter to ‘strtaglen’ might point past the end of an
allocation.  Therefore, if ‘start’ becomes equal to ‘end’, exit the loop
without calling ‘memchr’ on it.
  • Loading branch information
DemiMarie authored and pmatilai committed Feb 18, 2021
1 parent 210198b commit 165330b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/header.c
Expand Up @@ -412,10 +412,8 @@ static inline int strtaglen(const char *str, rpm_count_t c, const char *end)
const char *s;

if (end) {
if (str >= end)
return -1;
while ((s = memchr(start, '\0', end-start))) {
if (--c == 0 || s > end)
while (end > start && (s = memchr(start, '\0', end-start))) {
if (--c == 0)
break;
start = s + 1;
}
Expand Down

0 comments on commit 165330b

Please sign in to comment.