Skip to contentSkip to conversation

cmd: Fix potential NULL pointer dereference

PATCH In review Pavel Borzenkov 2 participants 3 messages Oct 28, 2011 – Oct 31, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd: Fix potential NULL pointer dereference

---
Note, that almost all code in the file violates CODING STYLE. The changed lines are written wrt CODING STYLE (like commits 7d7d975c and c32d766a).
---

 cmd.c |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)
cmd.c +3 -8
index f77897e..abcf206 100644
@@ -49,7 +49,7 @@ void
 add_command(
 	const cmdinfo_t	*ci)
 {
-	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+    cmdtab = g_realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
 	cmdtab[ncmds - 1] = *ci;
 	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
 }
@@ -125,12 +125,7 @@ find_command(
 void
 add_user_command(char *optarg)
 {
-	ncmdline++;
-	cmdline = realloc(cmdline, sizeof(char*) * (ncmdline));
-	if (!cmdline) {
-		perror("realloc");
-		exit(1);
-	}
+    cmdline = g_realloc(cmdline, ++ncmdline * sizeof(char *));
 	cmdline[ncmdline-1] = optarg;
 }
 
@@ -194,7 +189,7 @@ command_loop(void)
 		doneline(input, v);
 	}
 	if (cmdline) {
-		free(cmdline);
+        g_free(cmdline);
 		return;
 	}
 
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 15 lines · Pavel Borzenkov

---
Note, that almost all code in the file violates CODING STYLE. The changed lines are written wrt CODING STYLE (like commits 7d7d975c and c32d766a).

---

 cmd.c |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)
cmd.c +0 -0
index f77897e..abcf206 100644

cmd.c void · line 55

Quoted 8 lines
cmd.c +1 -1
@@ -49,7 +49,7 @@ void
 add_command(
 	const cmdinfo_t	*ci)
 {
-	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+    cmdtab = g_realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
 	cmdtab[ncmds - 1] = *ci;
 	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
 }

Inconsistent indentation.

Either stick to the original indentation, or reindent the whole function.

[More of the same...]

#2 lore raw
Quoted 28 lines · Markus Armbruster
Quoted 15 lines · Pavel Borzenkov

---
Note, that almost all code in the file violates CODING STYLE. The changed lines are written wrt CODING STYLE (like commits 7d7d975c and c32d766a).

---

 cmd.c |   11 +++--------

 1 files changed, 3 insertions(+), 8 deletions(-)
cmd.c +0 -0
index f77897e..abcf206 100644
@@ -49,7 +49,7 @@ void
Quoted 8 lines

 add_command(
      const cmdinfo_t *ci)
 {
-     cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+    cmdtab = g_realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab)); cmdtab[ncmds - 1] = *ci;
      qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
 }

Inconsistent indentation.

Quoted 2 lines

Either stick to the original indentation, or reindent the whole function.

I'll send second version with coding style fixes made in a separate commit.

Signature · 1 line
Pavel
Quoted 3 lines

[More of the same...]