fix unlikely NULL pointer deref in kallsyms
PATCH 1/1 fix unlikely NULL pointer deref in kallsyms
The Coverity checker noticed that kallsyms may dereference a NULL pointer (in two places) in the function write_src() if malloc() fails. In addition, malloc() returns a void*, so there's no need to cast the return value.
The amount requested is small, so this is unlikely to happen, but not impossible.
To fix the problem, if malloc() should fail, print a descriptive error and exit.
A lot better than just dereferencing a NULL pointer and crashing.
This fixes coverity bug #398
Signed-off-by Jesper Juhl <[email protected]>
---
scripts/kallsyms.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletion(-)
scripts/kallsyms.c +6 -1
@@ -272,7 +272,12 @@ static void write_src(void)/* table of offset markers, that give the offset in the compressed stream * every 256 symbols */ - markers = (unsigned int *)malloc (sizeof (unsigned int ) * ((table_cnt +255 ) /256 )); + markers =malloc (sizeof (unsigned int ) * ((table_cnt +255 ) /256 )); +if (!markers) { +fprintf (stderr,"kallsyms failure: " +"unable to allocate required memory\n" ); +exit (EXIT_FAILURE ); + }output_label ("kallsyms_names" ); off =0 ;