1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-15 10:17:20 +00:00

dispatch_add_command:

Modify the logic so there's only one exit point instead of two.
Only insert valid (non-NULL) values into the queue.

dispatch_free_command:
Ensure that item is not NULL before removing it from the queue and
dereferencing the pointer.
NULL out free'd pointers to catch any use-after-free bugs.

PR:	bin/146855
Submitted by:	gcooper
MFC after: 3 days
This commit is contained in:
Rebecca Cran 2010-11-21 14:34:25 +00:00
parent c86bcbb3a7
commit f22de230a1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=215637

View File

@ -136,8 +136,12 @@ typedef struct command_buffer_ {
static void
dispatch_free_command(command_buffer *item)
{
REMQUE(item);
free(item->string);
if (item != NULL) {
REMQUE(item);
free(item->string);
item->string = NULL;
}
free(item);
}
@ -155,19 +159,29 @@ dispatch_free_all(qelement *head)
static command_buffer *
dispatch_add_command(qelement *head, char *string)
{
command_buffer *new;
command_buffer *new = NULL;
new = malloc(sizeof(command_buffer));
if (!new)
return NULL;
if (new != NULL) {
new->string = strdup(string);
INSQUEUE(new, head->q_back);
new->string = strdup(string);
/*
* We failed to copy `string'; clean up the allocated
* resources.
*/
if (new->string == NULL) {
free(new);
new = NULL;
} else {
INSQUEUE(new, head->q_back);
}
}
return new;
}
/*
* Command processing
*/
@ -280,7 +294,7 @@ dispatchCommand(char *str)
return i;
}
/*
* File processing
*/