public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] docproc: handle realloc() failure in find_all_symbols()
@ 2015-02-28 20:07 Arjun Sreedharan
  0 siblings, 0 replies; only message in thread
From: Arjun Sreedharan @ 2015-02-28 20:07 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Michal Marek, lkml

check realloc rc and avoid potential null dereference
and memory leak

Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>
---
 scripts/docproc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/docproc.c b/scripts/docproc.c
index e267e621..438fc91 100644
--- a/scripts/docproc.c
+++ b/scripts/docproc.c
@@ -396,6 +396,10 @@ static void find_all_symbols(char *filename)
 						   4096)) > 0) {
 					data_len += ret;
 					data = realloc(data, data_len + 4096);
+					if (data == NULL) {
+						perror("realloc");
+						exit(1);
+					}
 				}
 			} while (ret == -EAGAIN);
 			if (ret != 0) {
@@ -420,6 +424,10 @@ static void find_all_symbols(char *filename)
 	start = all_list_len;
 	all_list_len += count;
 	all_list = realloc(all_list, sizeof(char *) * all_list_len);
+	if (all_list == NULL) {
+		perror("realloc");
+		exit(1);
+	}
 	str = data;
 	for (i = 0; i < data_len && start != all_list_len; i++) {
 		if (data[i] == '\0') {
-- 
1.8.1.msysgit.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-28 20:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-28 20:07 [PATCH] docproc: handle realloc() failure in find_all_symbols() Arjun Sreedharan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox