Page MenuHomePhabricator

gssapi: detect malloc failure
Closed, ResolvedPublic

Description

Hi,

malloc(n) returns NULL on failure.
malloc(0) may return NULL.

Patch:

Author: raminfp <ramin.blackhat@gmail.com> 
Date:   Wed Mar 20 20:56:33 2019 +0000 

   malloc will return NULL 

diff --git a/src/gssapi.c b/src/gssapi.c 
index f2ca38df..a30b5590 100644 
--- a/src/gssapi.c 
+++ b/src/gssapi.c 
@@ -328,7 +328,9 @@ static char *ssh_gssapi_name_to_char(gss_name_t name){ 
                         "converting name", 
                         maj_stat, 
                         min_stat); 
-    ptr=malloc(buffer.length + 1); 
+    ptr = malloc(buffer.length + 1); 
+    if(ptr == NULL) 
+       return NULL; 
    memcpy(ptr, buffer.value, buffer.length); 
    ptr[buffer.length] = '\0'; 
    gss_release_buffer(&min_stat, &buffer);

Event Timeline

raminfp created this task.Apr 1 2019, 10:50 AM

Hello,

Thank you for reporting this and sending you patch proposal.

Can you send your patch proposal as a merge request at https://gitlab.com/libssh/libssh-mirror ?

And please add your signoff as described in the SubmittingPatches file.

Thank you

asn added a project: Restricted Project.Apr 29 2019, 10:40 AM