diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-08-04 20:16:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-08-04 20:16:10 +0000 |
commit | a4f6f3b0d403d43eecc61ecc4312413c64d63c6c (patch) | |
tree | 5b189d2f8b76a178559efd1aae851fbc6d39407a /src/main/extractor_ipc_gnu.c | |
parent | 0c700e7ddaa315989fa0b5d301fe24be0f3b72d1 (diff) | |
download | libextractor-a4f6f3b0d403d43eecc61ecc4312413c64d63c6c.tar.gz libextractor-a4f6f3b0d403d43eecc61ecc4312413c64d63c6c.zip |
fix recursive strtok issue by using strtok_r
Diffstat (limited to 'src/main/extractor_ipc_gnu.c')
-rw-r--r-- | src/main/extractor_ipc_gnu.c | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c index accfc5b..a5854d3 100644 --- a/src/main/extractor_ipc_gnu.c +++ b/src/main/extractor_ipc_gnu.c | |||
@@ -84,10 +84,13 @@ struct EXTRACTOR_Channel | |||
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Buffer for reading data from the plugin. | 86 | * Buffer for reading data from the plugin. |
87 | * FIXME: we might want to grow this | ||
88 | * buffer dynamically instead of always using 32 MB! | ||
89 | */ | 87 | */ |
90 | char data[MAX_META_DATA]; | 88 | char *mdata; |
89 | |||
90 | /** | ||
91 | * Size of the 'mdata' buffer. | ||
92 | */ | ||
93 | size_t mdata_size; | ||
91 | 94 | ||
92 | /** | 95 | /** |
93 | * Memory segment shared with this process. | 96 | * Memory segment shared with this process. |
@@ -280,6 +283,13 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, | |||
280 | LOG_STRERROR ("malloc"); | 283 | LOG_STRERROR ("malloc"); |
281 | return NULL; | 284 | return NULL; |
282 | } | 285 | } |
286 | channel->mdata_size = 1024; | ||
287 | if (NULL == (channel->mdata = malloc (channel->mdata_size))) | ||
288 | { | ||
289 | LOG_STRERROR ("malloc"); | ||
290 | free (channel); | ||
291 | return NULL; | ||
292 | } | ||
283 | channel->shm = shm; | 293 | channel->shm = shm; |
284 | channel->plugin = plugin; | 294 | channel->plugin = plugin; |
285 | channel->size = 0; | 295 | channel->size = 0; |
@@ -367,6 +377,7 @@ EXTRACTOR_IPC_channel_destroy_ (struct EXTRACTOR_Channel *channel) | |||
367 | LOG_STRERROR ("close"); | 377 | LOG_STRERROR ("close"); |
368 | if (0 != close (channel->cpipe_in)) | 378 | if (0 != close (channel->cpipe_in)) |
369 | LOG_STRERROR ("close"); | 379 | LOG_STRERROR ("close"); |
380 | free (channel->mdata); | ||
370 | free (channel); | 381 | free (channel); |
371 | } | 382 | } |
372 | 383 | ||
@@ -432,6 +443,7 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, | |||
432 | struct EXTRACTOR_Channel *channel; | 443 | struct EXTRACTOR_Channel *channel; |
433 | ssize_t ret; | 444 | ssize_t ret; |
434 | ssize_t iret; | 445 | ssize_t iret; |
446 | char *ndata; | ||
435 | 447 | ||
436 | FD_ZERO (&to_check); | 448 | FD_ZERO (&to_check); |
437 | max = -1; | 449 | max = -1; |
@@ -464,12 +476,33 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, | |||
464 | continue; | 476 | continue; |
465 | if (! FD_ISSET (channel->cpipe_out, &to_check)) | 477 | if (! FD_ISSET (channel->cpipe_out, &to_check)) |
466 | continue; | 478 | continue; |
479 | if (channel->mdata_size == channel->size) | ||
480 | { | ||
481 | /* not enough space, need to grow allocation (if allowed) */ | ||
482 | if (MAX_META_DATA == channel->mdata_size) | ||
483 | { | ||
484 | LOG ("Inbound message from channel too large, aborting\n"); | ||
485 | EXTRACTOR_IPC_channel_destroy_ (channel); | ||
486 | channels[i] = NULL; | ||
487 | } | ||
488 | channel->mdata_size *= 2; | ||
489 | if (channel->mdata_size > MAX_META_DATA) | ||
490 | channel->mdata_size = MAX_META_DATA; | ||
491 | if (NULL == (ndata = realloc (channel->mdata, | ||
492 | channel->mdata_size))) | ||
493 | { | ||
494 | LOG_STRERROR ("realloc"); | ||
495 | EXTRACTOR_IPC_channel_destroy_ (channel); | ||
496 | channels[i] = NULL; | ||
497 | } | ||
498 | channel->mdata = ndata; | ||
499 | } | ||
467 | if ( (-1 == (iret = read (channel->cpipe_out, | 500 | if ( (-1 == (iret = read (channel->cpipe_out, |
468 | &channel->data[channel->size], | 501 | &channel->mdata[channel->size], |
469 | MAX_META_DATA - channel->size)) ) || | 502 | channel->mdata_size - channel->size)) ) || |
470 | (0 == iret) || | 503 | (0 == iret) || |
471 | (-1 == (ret = EXTRACTOR_IPC_process_reply_ (channel->plugin, | 504 | (-1 == (ret = EXTRACTOR_IPC_process_reply_ (channel->plugin, |
472 | channel->data, | 505 | channel->mdata, |
473 | channel->size + iret, | 506 | channel->size + iret, |
474 | proc, proc_cls)) ) ) | 507 | proc, proc_cls)) ) ) |
475 | { | 508 | { |
@@ -480,8 +513,8 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, | |||
480 | } | 513 | } |
481 | else | 514 | else |
482 | { | 515 | { |
483 | memmove (channel->data, | 516 | memmove (channel->mdata, |
484 | &channel->data[ret], | 517 | &channel->mdata[ret], |
485 | channel->size + iret - ret); | 518 | channel->size + iret - ret); |
486 | channel->size = channel->size + iret - ret; | 519 | channel->size = channel->size + iret - ret; |
487 | } | 520 | } |