Skip to content

Commit

Permalink
Fix possible NULL dereference
Browse files Browse the repository at this point in the history
Fixes following issue as reported by GCC-10 static analyzer:

 multipart_parser.c: In function ‘multipart_parser_init’:
 multipart_parser.c:88:22: error: dereference of possibly-NULL ‘p’ [CWE-690] [-Werror=analyzer-possible-null-dereference]

   88 |   p->boundary_length = strlen(boundary);
      |   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
  ‘multipart_parser_init’: events 1-2
    |
    |   83 |   multipart_parser* p = malloc(sizeof(multipart_parser) +
    |      |   ^~~~~~~~~~~~~~~~
    |      |   |
    |      |   (1) this call could return NULL
    |......
    |   88 |   p->boundary_length = strlen(boundary);
    |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                      |
    |      |                      (2) ‘p’ could be NULL: unchecked value from (1)

Signed-off-by: Petr Štetiar <ynezz@true.cz>
  • Loading branch information
ynezz committed Oct 27, 2020
1 parent 8e5719b commit 232659d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions multipart_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ multipart_parser* multipart_parser_init
strlen(boundary) +
strlen(boundary) + 9);

if (!p)
return NULL;

strcpy(p->multipart_boundary, boundary);
p->boundary_length = strlen(boundary);

Expand Down

0 comments on commit 232659d

Please sign in to comment.