Author: brucec
Date: Wed Nov 24 21:58:15 2010
New Revision: 215807
URL: http://svn.freebsd.org/changeset/base/215807

Log:
  MFC r215637:
  
  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

Modified:
  stable/7/usr.sbin/sysinstall/dispatch.c
Directory Properties:
  stable/7/usr.sbin/sysinstall/   (props changed)

Modified: stable/7/usr.sbin/sysinstall/dispatch.c
==============================================================================
--- stable/7/usr.sbin/sysinstall/dispatch.c     Wed Nov 24 21:57:45 2010        
(r215806)
+++ stable/7/usr.sbin/sysinstall/dispatch.c     Wed Nov 24 21:58:15 2010        
(r215807)
@@ -135,8 +135,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);
 }
 
@@ -154,19 +158,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
  */
@@ -278,7 +292,7 @@ dispatchCommand(char *str)
     return i;
 }
 
-
+
 /*
  * File processing
  */
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to