Fix possible NULL dereference
authorPetr Štetiar <ynezz@true.cz>
Sun, 11 Oct 2020 08:56:24 +0000 (10:56 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 27 Oct 2020 22:03:04 +0000 (23:03 +0100)
commit232659da19a4c08c499735fa0a07abc9b3cf3c73
treebbf99db7512149835edf8db26ac9e8582f4d7188
parent8e5719b37a67925674bb3c5524a1ad3fa138a064
Fix possible NULL dereference

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>
multipart_parser.c