diff options
Diffstat (limited to 'src/plugins/zip_extractor.c')
-rw-r--r-- | src/plugins/zip_extractor.c | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/src/plugins/zip_extractor.c b/src/plugins/zip_extractor.c index c7fef95..c7bc936 100644 --- a/src/plugins/zip_extractor.c +++ b/src/plugins/zip_extractor.c | |||
@@ -88,7 +88,7 @@ EXTRACTOR_zip_extract (const unsigned char *data, | |||
88 | void *tmp; | 88 | void *tmp; |
89 | zip_entry * info; | 89 | zip_entry * info; |
90 | zip_entry * start; | 90 | zip_entry * start; |
91 | char *filecomment = NULL; | 91 | char *filecomment; |
92 | const unsigned char *pos; | 92 | const unsigned char *pos; |
93 | unsigned int offset, stop; | 93 | unsigned int offset, stop; |
94 | unsigned int name_length, extra_length, comment_length; | 94 | unsigned int name_length, extra_length, comment_length; |
@@ -174,8 +174,11 @@ EXTRACTOR_zip_extract (const unsigned char *data, | |||
174 | if (filecomment_length > 0) | 174 | if (filecomment_length > 0) |
175 | { | 175 | { |
176 | filecomment = malloc (filecomment_length + 1); | 176 | filecomment = malloc (filecomment_length + 1); |
177 | memcpy (filecomment, &pos[22], filecomment_length); | 177 | if (filecomment != NULL) |
178 | filecomment[filecomment_length] = '\0'; | 178 | { |
179 | memcpy (filecomment, &pos[22], filecomment_length); | ||
180 | filecomment[filecomment_length] = '\0'; | ||
181 | } | ||
179 | } | 182 | } |
180 | if ((0 != pos[4]) && (0 != pos[5])) | 183 | if ((0 != pos[4]) && (0 != pos[5])) |
181 | { | 184 | { |
@@ -281,12 +284,16 @@ EXTRACTOR_zip_extract (const unsigned char *data, | |||
281 | if (start == NULL) | 284 | if (start == NULL) |
282 | { | 285 | { |
283 | start = malloc (sizeof (zip_entry)); | 286 | start = malloc (sizeof (zip_entry)); |
287 | if (start == NULL) | ||
288 | break; | ||
284 | start->next = NULL; | 289 | start->next = NULL; |
285 | info = start; | 290 | info = start; |
286 | } | 291 | } |
287 | else | 292 | else |
288 | { | 293 | { |
289 | info->next = malloc (sizeof (zip_entry)); | 294 | info->next = malloc (sizeof (zip_entry)); |
295 | if (info->next == NULL) | ||
296 | break; | ||
290 | info = info->next; | 297 | info = info->next; |
291 | info->next = NULL; | 298 | info->next = NULL; |
292 | } | 299 | } |
@@ -294,35 +301,36 @@ EXTRACTOR_zip_extract (const unsigned char *data, | |||
294 | info->comment = malloc (comment_length + 1); | 301 | info->comment = malloc (comment_length + 1); |
295 | 302 | ||
296 | /* (strings in zip files are not null terminated) */ | 303 | /* (strings in zip files are not null terminated) */ |
297 | memcpy (info->filename, &pos[46], name_length); | 304 | if (info->filename != NULL) |
298 | info->filename[name_length] = '\0'; | 305 | { |
299 | memcpy (info->comment, &pos[46 + name_length + extra_length], | 306 | memcpy (info->filename, &pos[46], name_length); |
300 | comment_length); | 307 | info->filename[name_length] = '\0'; |
301 | info->comment[comment_length] = '\0'; | 308 | } |
302 | 309 | if (info->comment != NULL) | |
303 | #if DEBUG_EXTRACT_ZIP | 310 | { |
304 | fprintf (stderr, "Found file %s, Comment: %s\n", info->filename, | 311 | memcpy (info->comment, &pos[46 + name_length + extra_length], |
305 | info->comment); | 312 | comment_length); |
306 | 313 | info->comment[comment_length] = '\0'; | |
307 | #endif | 314 | } |
308 | offset += 46 + name_length + extra_length + comment_length; | 315 | offset += 46 + name_length + extra_length + comment_length; |
309 | pos = &data[offset]; | 316 | pos = &data[offset]; |
310 | 317 | /* check for next header entry (0x02014b50) or (0x06054b50) if at end */ | |
311 | /* check for next header entry (0x02014b50) or (0x06054b50) if at end */ | 318 | if (('P' != pos[0]) && ('K' != pos[1])) |
312 | if (('P' != pos[0]) && ('K' != pos[1])) | ||
313 | { | 319 | { |
314 | 320 | ||
315 | #if DEBUG_EXTRACT_ZIP | 321 | #if DEBUG_EXTRACT_ZIP |
316 | fprintf (stderr, | 322 | fprintf (stderr, |
317 | "Did not find next header in central directory.\n"); | 323 | "Did not find next header in central directory.\n"); |
318 | 324 | ||
319 | #endif | 325 | #endif |
320 | info = start; | 326 | info = start; |
321 | while (info != NULL) | 327 | while (info != NULL) |
322 | { | 328 | { |
323 | start = info->next; | 329 | start = info->next; |
324 | free (info->filename); | 330 | if (info->filename != NULL) |
325 | free (info->comment); | 331 | free (info->filename); |
332 | if (info->comment != NULL) | ||
333 | free (info->comment); | ||
326 | free (info); | 334 | free (info); |
327 | info = start; | 335 | info = start; |
328 | } | 336 | } |
@@ -364,7 +372,8 @@ EXTRACTOR_zip_extract (const unsigned char *data, | |||
364 | filecomment, | 372 | filecomment, |
365 | strlen (filecomment)+1); | 373 | strlen (filecomment)+1); |
366 | } | 374 | } |
367 | free (filecomment); | 375 | if (filecomment != NULL) |
376 | free (filecomment); | ||
368 | 377 | ||
369 | 378 | ||
370 | /* if we've gotten to here then there is at least one zip entry (see get_zipinfo call above) */ | 379 | /* if we've gotten to here then there is at least one zip entry (see get_zipinfo call above) */ |