fix potential null deref in kallsyms::read_symbol
PATCH 1/1 fix potential null deref in kallsyms::read_symbol
The Coverity checker found that if malloc() fails in scripts/kallsyms.c::read_symbol() then we end up dereferencing a NULL pointer.
Unlikely to happen, but we really should check the malloc() return value. This patch fixes the problem by checking the return value and printing a nice descriptive error message and exiting if malloc() did fail.
This fixes coverity error #397
Signed-off-by Jesper Juhl <[email protected]>
---
scripts/kallsyms.c | 5 +++++ 1 files changed, 5 insertions(+)
scripts/kallsyms.c +5 -0
@@ -124,6 +124,11 @@ static int read_symbol(FILE *in, struct* compressed together */ s->len =strlen (str) +1 ; s->sym =malloc (s->len +1 ); +if (!s->sym) { +fprintf (stderr,"kallsyms failure: " +"unable to allocate required amount of memory\n" ); +exit (EXIT_FAILURE ); + }strcpy ((char *)s->sym +1 , str); s->sym[0 ] = stype;