Menu

#19 Dereferencing a possible NULL Pointer without NULL check in mmsh.c

v1.0 (example)
closed-accepted
nobody
None
5
2015-11-19
2015-11-09
No

Version : libmms-0.6.4
file : mmsh.c
line no : 606
NULL check is missing on pointer before dereferencing it.
In file mmsh.c, calloc is being used for memory allocation and retured pointer is assigned to variable ‘this’.
Variable 'this' is dereferenced in file mms.c at line no 606, without null check.

Current code :

this = (mms_t*)calloc(1, sizeof(mmsh_t));

this->url = strdup (url);
this->s = -1;

Suggested code :

this = calloc(1, sizeof(mmsh_t));

if (!this) {
lprintf("error, calloc failed\n");
return NULL;
}

this->url = strdup(url);

this->s = -1;

Please check the attached patch.

1 Attachments

Discussion

  • Hans de Goede

    Hans de Goede - 2015-11-19

    Thanks for the patch, applied and pushed to git master.

     
  • Hans de Goede

    Hans de Goede - 2015-11-19
    • status: open --> closed-accepted
     

Log in to post a comment.

MongoDB Logo MongoDB