Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
cmd: Fix potential NULL pointer dereference
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
  • Loading branch information
pborzenkov authored and Stefan Hajnoczi committed Nov 7, 2011
1 parent 81beeec commit ba7806a
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions cmd.c
Expand Up @@ -47,7 +47,7 @@ compare(const void *a, const void *b)

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);
}
Expand Down Expand Up @@ -122,12 +122,7 @@ find_command(

void add_user_command(char *optarg)
{
ncmdline++;
cmdline = realloc(cmdline, ncmdline * sizeof(char *));
if (!cmdline) {
perror("realloc");
exit(1);
}
cmdline = g_realloc(cmdline, ++ncmdline * sizeof(char *));
cmdline[ncmdline-1] = optarg;
}

Expand Down Expand Up @@ -190,7 +185,7 @@ void command_loop(void)
doneline(input, v);
}
if (cmdline) {
free(cmdline);
g_free(cmdline);
return;
}

Expand Down

0 comments on commit ba7806a

Please sign in to comment.