Skip to content
  • Antonio Borneo's avatar
    helper/command: check for malloc failure in __command_name · c4a7a622
    Antonio Borneo authored
    
    
    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. Plus, in one case it
    overwrites an already detected error.
    
    Check the pointer returned by malloc and, in case of failure,
    issue an error message and return the NULL pointer.
    Let the caller of command_name() to keep the already detected
    error or to return ERROR_FAIL in case of end of memory.
    
    Change-Id: I151a24569409777dd5bc09a3daf5dba2b8e2829b
    Signed-off-by: default avatarAntonio Borneo <borneo.antonio@gmail.com>
    Reviewed-on: http://openocd.zylin.com/4838
    
    
    Tested-by: jenkins
    Reviewed-by: default avatarTomas Vanek <vanekt@fbl.cz>
    c4a7a622