This is an automated email from Gerrit.

Antonio Borneo ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/4838

-- gerrit

commit dc4761f0f4776178d121e214d86f2c1ece57f5e2
Author: Antonio Borneo <[email protected]>
Date:   Tue Jan 8 09:54:30 2019 +0100

    helper/command: check for malloc failure in __command_name
    
    If malloc fails in __command_name, the following strcpy will
    segfault, thus preventing __command_name to return.
    The actual calls to command_name() implement the correct check
    for the NULL pointer, but propagate error -ENOMEM, that is not
    an error value coherent within OpenOCD.
    
    Check the pointer returned by malloc, issue an error message and
    return the NULL pointer.
    Let the caller of command_name() to return ERROR_FAIL in case of
    end of memory.
    
    Change-Id: I151a24569409777dd5bc09a3daf5dba2b8e2829b
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/src/helper/command.c b/src/helper/command.c
index 35c4486..f33cbdd 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -557,6 +557,10 @@ static char *__command_name(struct command *c, char delim, 
unsigned extra)
        if (NULL == c->parent) {
                /* allocate enough for the name, child names, and '\0' */
                name = malloc(len + extra + 1);
+               if (!name) {
+                       LOG_ERROR("Out of memory");
+                       return NULL;
+               }
                strcpy(name, c->name);
        } else {
                /* parent's extra must include both the space and name */
@@ -632,7 +636,7 @@ static int run_command(struct command_context *context,
                        command_run_linef(context, "usage %s", full_name);
                        free(full_name);
                } else
-                       retval = -ENOMEM;
+                       retval = ERROR_FAIL;
        } else if (retval == ERROR_COMMAND_CLOSE_CONNECTION) {
                /* just fall through for a shutdown request */
        } else if (retval != ERROR_OK) {
@@ -870,7 +874,7 @@ static COMMAND_HELPER(command_help_show, struct command *c, 
unsigned n,
 {
        char *cmd_name = command_name(c, ' ');
        if (NULL == cmd_name)
-               return -ENOMEM;
+               return ERROR_FAIL;
 
        /* If the match string occurs anywhere, we print out
         * stuff for this command. */

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to