Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] kbuild: fix buffer overflow in modpost

Jiri Benc <jbenc@suse.cz> reported that modpost would stop with SIGABRT if
used with long filepaths.
The error looked like:
> Building modules, stage 2.
> MODPOST
> *** glibc detected *** scripts/mod/modpost: realloc(): invalid next size:
+0x0809f588 ***
> [...]

Fix this by allocating at least the required memory + SZ bytes each time.
Before we sometimes ended up allocating too little memory resuting in the
glibc detected bug above. Based on patch originally submitted by: Jiri
Benc <jbenc@suse.cz>

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Sam Ravnborg and committed by
Linus Torvalds
7670f023 85c6932e

+2 -7
+2 -7
scripts/mod/modpost.c
··· 508 508 509 509 va_start(ap, fmt); 510 510 len = vsnprintf(tmp, SZ, fmt, ap); 511 - if (buf->size - buf->pos < len + 1) { 512 - buf->size += 128; 513 - buf->p = realloc(buf->p, buf->size); 514 - } 515 - strncpy(buf->p + buf->pos, tmp, len + 1); 516 - buf->pos += len; 511 + buf_write(buf, tmp, len); 517 512 va_end(ap); 518 513 } 519 514 ··· 516 521 buf_write(struct buffer *buf, const char *s, int len) 517 522 { 518 523 if (buf->size - buf->pos < len) { 519 - buf->size += len; 524 + buf->size += len + SZ; 520 525 buf->p = realloc(buf->p, buf->size); 521 526 } 522 527 strncpy(buf->p + buf->pos, s, len);