* PROBLEM: linux 2.6.13.4 (snapgear-3.3.0) scripts/mod/modpost dumps core
@ 2005-11-18 22:04 Jeff Johnson
0 siblings, 0 replies; only message in thread
From: Jeff Johnson @ 2005-11-18 22:04 UTC (permalink / raw)
To: linux-kernel
I'm new at this, so hopefully this is OK. I'm working on an embedded
system using snapgear-3.3.0 (linux 2.6.13.4). The kernel build fails
when executing modpost -- it dumps core. I have debugged the problem.
In modpost.c:buf_printf() appears the following code:
len = vsnprintf(tmp, SZ, fmt, ap);
if (buf->size - buf->pos < len + 1) {
buf->size += 128;
buf->p = realloc(buf->p, buf->size);
}
strncpy(buf->p + buf->pos, tmp, len + 1);
What I have discovered is that in my environment, in some cases the
output from vsnprintf() exceeds 128 characters. So when the test for
"remaining space < len" fails, and the buf is realloc'ed, not enough
memory is allocated, and the subsequent strncpy overflows the buffer.
My solution was to change the assignment of buf->size as follows:
buf->size += 128 * ((len/128)+1);
This will cause buf->size to increment by enough 128 byte blocks to
hold the string. If it isn't important to increment in 128 byte
chunks, then I suppose you could just have:
buf->size += SZ;
Thanks
Jeff
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-11-18 22:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-18 22:04 PROBLEM: linux 2.6.13.4 (snapgear-3.3.0) scripts/mod/modpost dumps core Jeff Johnson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®