mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Juhl <jesper.juhl@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@osdl.org>, Jesper Juhl <jesper.juhl@gmail.com>
Subject: [PATCH] fix unlikely NULL pointer deref in kallsyms
Date: Thu, 9 Mar 2006 22:48:47 +0100	[thread overview]
Message-ID: <200603092248.47344.jesper.juhl@gmail.com> (raw)


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 <jesper.juhl@gmail.com>
---

 scripts/kallsyms.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletion(-)

--- linux-2.6.16-rc5-git12-orig/scripts/kallsyms.c	2006-01-03 04:21:10.000000000 +0100
+++ linux-2.6.16-rc5-git12/scripts/kallsyms.c	2006-03-09 22:41:17.000000000 +0100
@@ -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;




                 reply	other threads:[~2006-03-09 21:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200603092248.47344.jesper.juhl@gmail.com \
    --to=jesper.juhl@gmail.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome