aboutsummaryrefslogtreecommitdiff
path: root/src/main/extractor_plugin_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/extractor_plugin_main.c')
-rw-r--r--src/main/extractor_plugin_main.c524
1 files changed, 262 insertions, 262 deletions
diff --git a/src/main/extractor_plugin_main.c b/src/main/extractor_plugin_main.c
index 7b01140..fd4912f 100644
--- a/src/main/extractor_plugin_main.c
+++ b/src/main/extractor_plugin_main.c
@@ -116,8 +116,8 @@ struct ProcessingContext
116 */ 116 */
117static int64_t 117static int64_t
118plugin_env_seek (void *cls, 118plugin_env_seek (void *cls,
119 int64_t pos, 119 int64_t pos,
120 int whence) 120 int whence)
121{ 121{
122 struct ProcessingContext *pc = cls; 122 struct ProcessingContext *pc = cls;
123 struct SeekRequestMessage srm; 123 struct SeekRequestMessage srm;
@@ -127,117 +127,118 @@ plugin_env_seek (void *cls,
127 uint16_t wval; 127 uint16_t wval;
128 128
129 switch (whence) 129 switch (whence)
130 {
131 case SEEK_CUR:
132 if ( (pos < 0) && (pc->read_position < -pos) )
130 { 133 {
131 case SEEK_CUR: 134 LOG ("Invalid seek operation\n");
132 if ( (pos < 0) && (pc->read_position < - pos) ) 135 return -1;
133 { 136 }
134 LOG ("Invalid seek operation\n"); 137 if ((pos > 0) && ((pc->read_position + pos < pc->read_position) ||
135 return -1; 138 (pc->read_position + pos > pc->file_size)))
136 } 139 {
137 if ((pos > 0) && ((pc->read_position + pos < pc->read_position) || 140 LOG ("Invalid seek operation\n");
138 (pc->read_position + pos > pc->file_size))) 141 return -1;
139 { 142 }
140 LOG ("Invalid seek operation\n"); 143 npos = (uint64_t) (pc->read_position + pos);
141 return -1; 144 wval = 0;
142 } 145 break;
143 npos = (uint64_t) (pc->read_position + pos); 146 case SEEK_END:
144 wval = 0; 147 if (pos > 0)
145 break; 148 {
146 case SEEK_END: 149 LOG ("Invalid seek operation\n");
147 if (pos > 0) 150 return -1;
148 { 151 }
149 LOG ("Invalid seek operation\n"); 152 if (UINT64_MAX == pc->file_size)
150 return -1; 153 {
151 } 154 wval = 2;
152 if (UINT64_MAX == pc->file_size) 155 npos = (uint64_t) -pos;
153 {
154 wval = 2;
155 npos = (uint64_t) - pos;
156 break;
157 }
158 pos = (int64_t) (pc->file_size + pos);
159 /* fall-through! */
160 case SEEK_SET:
161 if ( (pos < 0) || (pc->file_size < pos) )
162 {
163 LOG ("Invalid seek operation\n");
164 return -1;
165 }
166 npos = (uint64_t) pos;
167 wval = 0;
168 break; 156 break;
169 default: 157 }
158 pos = (int64_t) (pc->file_size + pos);
159 /* fall-through! */
160 case SEEK_SET:
161 if ( (pos < 0) || (pc->file_size < pos) )
162 {
170 LOG ("Invalid seek operation\n"); 163 LOG ("Invalid seek operation\n");
171 return -1; 164 return -1;
172 } 165 }
166 npos = (uint64_t) pos;
167 wval = 0;
168 break;
169 default:
170 LOG ("Invalid seek operation\n");
171 return -1;
172 }
173 if ( (pc->shm_off <= npos) && 173 if ( (pc->shm_off <= npos) &&
174 (pc->shm_off + pc->shm_ready_bytes > npos) && 174 (pc->shm_off + pc->shm_ready_bytes > npos) &&
175 (0 == wval) ) 175 (0 == wval) )
176 { 176 {
177 pc->read_position = npos; 177 pc->read_position = npos;
178 return (int64_t) npos; 178 return (int64_t) npos;
179 } 179 }
180 /* need to seek */ 180 /* need to seek */
181 srm.opcode = MESSAGE_SEEK; 181 srm.opcode = MESSAGE_SEEK;
182 srm.reserved = 0; 182 srm.reserved = 0;
183 srm.whence = wval; 183 srm.whence = wval;
184 srm.requested_bytes = pc->shm_map_size; 184 srm.requested_bytes = pc->shm_map_size;
185 if (0 == wval) 185 if (0 == wval)
186 { 186 {
187 if (srm.requested_bytes > pc->file_size - npos) 187 if (srm.requested_bytes > pc->file_size - npos)
188 srm.requested_bytes = pc->file_size - npos; 188 srm.requested_bytes = pc->file_size - npos;
189 } 189 }
190 else 190 else
191 { 191 {
192 srm.requested_bytes = npos; 192 srm.requested_bytes = npos;
193 } 193 }
194 srm.file_offset = npos; 194 srm.file_offset = npos;
195 if (-1 == EXTRACTOR_write_all_ (pc->out, &srm, sizeof (srm))) 195 if (-1 == EXTRACTOR_write_all_ (pc->out, &srm, sizeof (srm)))
196 { 196 {
197 LOG ("Failed to send MESSAGE_SEEK\n"); 197 LOG ("Failed to send MESSAGE_SEEK\n");
198 return -1; 198 return -1;
199 } 199 }
200 if (-1 == 200 if (-1 ==
201 EXTRACTOR_read_all_ (pc->in, 201 EXTRACTOR_read_all_ (pc->in,
202 &reply, sizeof (reply))) 202 &reply, sizeof (reply)))
203 { 203 {
204 LOG ("Plugin `%s' failed to read response to MESSAGE_SEEK\n", 204 LOG ("Plugin `%s' failed to read response to MESSAGE_SEEK\n",
205 pc->plugin->short_libname); 205 pc->plugin->short_libname);
206 return -1; 206 return -1;
207 } 207 }
208 if (MESSAGE_UPDATED_SHM != reply) 208 if (MESSAGE_UPDATED_SHM != reply)
209 { 209 {
210 LOG ("Unexpected reply %d to seek\n", reply); 210 LOG ("Unexpected reply %d to seek\n", reply);
211 return -1; /* was likely a MESSAGE_DISCARD_STATE */ 211 return -1; /* was likely a MESSAGE_DISCARD_STATE */
212 } 212 }
213 if (-1 == EXTRACTOR_read_all_ (pc->in, &um.reserved, sizeof (um) - 1)) 213 if (-1 == EXTRACTOR_read_all_ (pc->in, &um.reserved, sizeof (um) - 1))
214 { 214 {
215 LOG ("Failed to read MESSAGE_UPDATED_SHM\n"); 215 LOG ("Failed to read MESSAGE_UPDATED_SHM\n");
216 return -1; 216 return -1;
217 } 217 }
218 pc->shm_off = um.shm_off; 218 pc->shm_off = um.shm_off;
219 pc->shm_ready_bytes = um.shm_ready_bytes; 219 pc->shm_ready_bytes = um.shm_ready_bytes;
220 pc->file_size = um.file_size; 220 pc->file_size = um.file_size;
221 if (2 == wval) 221 if (2 == wval)
222 { 222 {
223 /* convert offset to be absolute from beginning of the file */ 223 /* convert offset to be absolute from beginning of the file */
224 npos = pc->file_size - npos; 224 npos = pc->file_size - npos;
225 } 225 }
226 if ( (pc->shm_off <= npos) && 226 if ( (pc->shm_off <= npos) &&
227 ((pc->shm_off + pc->shm_ready_bytes > npos) || 227 ((pc->shm_off + pc->shm_ready_bytes > npos) ||
228 (pc->file_size == pc->shm_off)) ) 228 (pc->file_size == pc->shm_off)) )
229 { 229 {
230 pc->read_position = npos; 230 pc->read_position = npos;
231 return (int64_t) npos; 231 return (int64_t) npos;
232 } 232 }
233 /* oops, serious missunderstanding, we asked to seek 233 /* oops, serious missunderstanding, we asked to seek
234 and then were notified about a different position!? */ 234 and then were notified about a different position!? */
235 LOG ("Plugin `%s' got invalid MESSAGE_UPDATED_SHM in response to my %d-seek (%llu not in %llu-%llu)\n", 235 LOG (
236 pc->plugin->short_libname, 236 "Plugin `%s' got invalid MESSAGE_UPDATED_SHM in response to my %d-seek (%llu not in %llu-%llu)\n",
237 (int) wval, 237 pc->plugin->short_libname,
238 (unsigned long long) npos, 238 (int) wval,
239 (unsigned long long) pc->shm_off, 239 (unsigned long long) npos,
240 (unsigned long long) pc->shm_off + pc->shm_ready_bytes); 240 (unsigned long long) pc->shm_off,
241 (unsigned long long) pc->shm_off + pc->shm_ready_bytes);
241 return -1; 242 return -1;
242} 243}
243 244
@@ -252,7 +253,7 @@ plugin_env_seek (void *cls,
252 */ 253 */
253static ssize_t 254static ssize_t
254plugin_env_read (void *cls, 255plugin_env_read (void *cls,
255 void **data, 256 void **data,
256 size_t count) 257 size_t count)
257{ 258{
258 struct ProcessingContext *pc = cls; 259 struct ProcessingContext *pc = cls;
@@ -266,10 +267,10 @@ plugin_env_read (void *cls,
266 (pc->read_position < pc->file_size)) || 267 (pc->read_position < pc->file_size)) ||
267 (pc->read_position < pc->shm_off) ) && 268 (pc->read_position < pc->shm_off) ) &&
268 (-1 == plugin_env_seek (pc, pc->read_position, SEEK_SET) ) ) 269 (-1 == plugin_env_seek (pc, pc->read_position, SEEK_SET) ) )
269 { 270 {
270 LOG ("Failed to seek to satisfy read\n"); 271 LOG ("Failed to seek to satisfy read\n");
271 return -1; 272 return -1;
272 } 273 }
273 if (pc->read_position + count > pc->shm_off + pc->shm_ready_bytes) 274 if (pc->read_position + count > pc->shm_off + pc->shm_ready_bytes)
274 count = pc->shm_off + pc->shm_ready_bytes - pc->read_position; 275 count = pc->shm_off + pc->shm_ready_bytes - pc->read_position;
275 dp = pc->shm; 276 dp = pc->shm;
@@ -313,12 +314,12 @@ plugin_env_get_size (void *cls)
313 */ 314 */
314static int 315static int
315plugin_env_send_proc (void *cls, 316plugin_env_send_proc (void *cls,
316 const char *plugin_name, 317 const char *plugin_name,
317 enum EXTRACTOR_MetaType type, 318 enum EXTRACTOR_MetaType type,
318 enum EXTRACTOR_MetaFormat format, 319 enum EXTRACTOR_MetaFormat format,
319 const char *data_mime_type, 320 const char *data_mime_type,
320 const char *data, 321 const char *data,
321 size_t data_len) 322 size_t data_len)
322{ 323{
323 struct ProcessingContext *pc = cls; 324 struct ProcessingContext *pc = cls;
324 struct MetaMessage mm; 325 struct MetaMessage mm;
@@ -340,32 +341,32 @@ plugin_env_send_proc (void *cls,
340 mm.mime_length = (uint16_t) mime_len; 341 mm.mime_length = (uint16_t) mime_len;
341 mm.value_size = (uint32_t) data_len; 342 mm.value_size = (uint32_t) data_len;
342 if ( (sizeof (mm) != 343 if ( (sizeof (mm) !=
343 EXTRACTOR_write_all_ (pc->out, 344 EXTRACTOR_write_all_ (pc->out,
344 &mm, sizeof (mm))) || 345 &mm, sizeof (mm))) ||
345 (mime_len != 346 (mime_len !=
346 EXTRACTOR_write_all_ (pc->out, 347 EXTRACTOR_write_all_ (pc->out,
347 data_mime_type, mime_len)) || 348 data_mime_type, mime_len)) ||
348 (data_len != 349 (data_len !=
349 EXTRACTOR_write_all_ (pc->out, 350 EXTRACTOR_write_all_ (pc->out,
350 data, data_len)) ) 351 data, data_len)) )
351 { 352 {
352 LOG ("Failed to send meta message\n"); 353 LOG ("Failed to send meta message\n");
353 return 1; 354 return 1;
354 } 355 }
355 if (-1 == 356 if (-1 ==
356 EXTRACTOR_read_all_ (pc->in, 357 EXTRACTOR_read_all_ (pc->in,
357 &reply, sizeof (reply))) 358 &reply, sizeof (reply)))
358 { 359 {
359 LOG ("Failed to read response to meta message\n"); 360 LOG ("Failed to read response to meta message\n");
360 return 1; 361 return 1;
361 } 362 }
362 if (MESSAGE_DISCARD_STATE == reply) 363 if (MESSAGE_DISCARD_STATE == reply)
363 return 1; 364 return 1;
364 if (MESSAGE_CONTINUE_EXTRACTING != reply) 365 if (MESSAGE_CONTINUE_EXTRACTING != reply)
365 { 366 {
366 LOG ("Received unexpected reply to meta data: %d\n", reply); 367 LOG ("Received unexpected reply to meta data: %d\n", reply);
367 return 1; 368 return 1;
368 } 369 }
369 return 0; 370 return 0;
370} 371}
371 372
@@ -382,34 +383,34 @@ handle_init_message (struct ProcessingContext *pc)
382 struct InitMessage init; 383 struct InitMessage init;
383 384
384 if (NULL != pc->shm) 385 if (NULL != pc->shm)
385 { 386 {
386 LOG ("Cannot handle 'init' message, have already been initialized\n"); 387 LOG ("Cannot handle 'init' message, have already been initialized\n");
387 return -1; 388 return -1;
388 } 389 }
389 if (sizeof (struct InitMessage) - 1 390 if (sizeof (struct InitMessage) - 1
390 != EXTRACTOR_read_all_ (pc->in, 391 != EXTRACTOR_read_all_ (pc->in,
391 &init.reserved, 392 &init.reserved,
392 sizeof (struct InitMessage) - 1)) 393 sizeof (struct InitMessage) - 1))
393 { 394 {
394 LOG ("Failed to read 'init' message\n"); 395 LOG ("Failed to read 'init' message\n");
395 return -1; 396 return -1;
396 } 397 }
397 if (init.shm_name_length > MAX_SHM_NAME) 398 if (init.shm_name_length > MAX_SHM_NAME)
398 { 399 {
399 LOG ("Invalid 'init' message\n"); 400 LOG ("Invalid 'init' message\n");
400 return -1; 401 return -1;
401 } 402 }
402 { 403 {
403 char shm_name[init.shm_name_length + 1]; 404 char shm_name[init.shm_name_length + 1];
404 405
405 if (init.shm_name_length 406 if (init.shm_name_length
406 != EXTRACTOR_read_all_ (pc->in, 407 != EXTRACTOR_read_all_ (pc->in,
407 shm_name, 408 shm_name,
408 init.shm_name_length)) 409 init.shm_name_length))
409 { 410 {
410 LOG ("Failed to read 'init' message\n"); 411 LOG ("Failed to read 'init' message\n");
411 return -1; 412 return -1;
412 } 413 }
413 shm_name[init.shm_name_length] = '\0'; 414 shm_name[init.shm_name_length] = '\0';
414 415
415 pc->shm_map_size = init.shm_map_size; 416 pc->shm_map_size = init.shm_map_size;
@@ -427,20 +428,20 @@ handle_init_message (struct ProcessingContext *pc)
427#else 428#else
428 pc->shm_id = shm_open (shm_name, O_RDONLY, 0); 429 pc->shm_id = shm_open (shm_name, O_RDONLY, 0);
429 if (-1 == pc->shm_id) 430 if (-1 == pc->shm_id)
430 { 431 {
431 LOG_STRERROR_FILE ("open", shm_name); 432 LOG_STRERROR_FILE ("open", shm_name);
432 return -1; 433 return -1;
433 } 434 }
434 pc->shm = mmap (NULL, 435 pc->shm = mmap (NULL,
435 pc->shm_map_size, 436 pc->shm_map_size,
436 PROT_READ, 437 PROT_READ,
437 MAP_SHARED, 438 MAP_SHARED,
438 pc->shm_id, 0); 439 pc->shm_id, 0);
439 if ( ((void*) -1) == pc->shm) 440 if ( ((void*) -1) == pc->shm)
440 { 441 {
441 LOG_STRERROR_FILE ("mmap", shm_name); 442 LOG_STRERROR_FILE ("mmap", shm_name);
442 return -1; 443 return -1;
443 } 444 }
444#endif 445#endif
445 } 446 }
446 return 0; 447 return 0;
@@ -462,12 +463,12 @@ handle_start_message (struct ProcessingContext *pc)
462 463
463 if (sizeof (struct StartMessage) - 1 464 if (sizeof (struct StartMessage) - 1
464 != EXTRACTOR_read_all_ (pc->in, 465 != EXTRACTOR_read_all_ (pc->in,
465 &start.reserved, 466 &start.reserved,
466 sizeof (struct StartMessage) - 1)) 467 sizeof (struct StartMessage) - 1))
467 { 468 {
468 LOG ("Failed to read 'start' message\n"); 469 LOG ("Failed to read 'start' message\n");
469 return -1; 470 return -1;
470 } 471 }
471 pc->shm_ready_bytes = start.shm_ready_bytes; 472 pc->shm_ready_bytes = start.shm_ready_bytes;
472 pc->file_size = start.file_size; 473 pc->file_size = start.file_size;
473 pc->read_position = 0; 474 pc->read_position = 0;
@@ -481,22 +482,22 @@ handle_start_message (struct ProcessingContext *pc)
481 pc->plugin->extract_method (&ec); 482 pc->plugin->extract_method (&ec);
482 done = MESSAGE_DONE; 483 done = MESSAGE_DONE;
483 if (-1 == EXTRACTOR_write_all_ (pc->out, &done, sizeof (done))) 484 if (-1 == EXTRACTOR_write_all_ (pc->out, &done, sizeof (done)))
484 { 485 {
485 LOG ("Failed to write 'done' message\n"); 486 LOG ("Failed to write 'done' message\n");
486 return -1; 487 return -1;
487 } 488 }
488 if ( (NULL != pc->plugin->specials) && 489 if ( (NULL != pc->plugin->specials) &&
489 (NULL != strstr (pc->plugin->specials, "force-kill")) ) 490 (NULL != strstr (pc->plugin->specials, "force-kill")) )
490 { 491 {
491 /* we're required to die after each file since this 492 /* we're required to die after each file since this
492 plugin only supports a single file at a time */ 493 plugin only supports a single file at a time */
493#if !WINDOWS 494#if ! WINDOWS
494 fsync (pc->out); 495 fsync (pc->out);
495#else 496#else
496 _commit (pc->out); 497 _commit (pc->out);
497#endif 498#endif
498 _exit (0); 499 _exit (0);
499 } 500 }
500 return 0; 501 return 0;
501} 502}
502 503
@@ -511,43 +512,43 @@ static void
511process_requests (struct ProcessingContext *pc) 512process_requests (struct ProcessingContext *pc)
512{ 513{
513 while (1) 514 while (1)
515 {
516 unsigned char code;
517
518 if (1 != EXTRACTOR_read_all_ (pc->in, &code, 1))
514 { 519 {
515 unsigned char code; 520 LOG ("Failed to read next request\n");
516 521 break;
517 if (1 != EXTRACTOR_read_all_ (pc->in, &code, 1))
518 {
519 LOG ("Failed to read next request\n");
520 break;
521 }
522 switch (code)
523 {
524 case MESSAGE_INIT_STATE:
525 if (0 != handle_init_message (pc))
526 {
527 LOG ("Failure to handle INIT\n");
528 return;
529 }
530 break;
531 case MESSAGE_EXTRACT_START:
532 if (0 != handle_start_message (pc))
533 {
534 LOG ("Failure to handle START\n");
535 return;
536 }
537 break;
538 case MESSAGE_UPDATED_SHM:
539 LOG ("Illegal message\n");
540 /* not allowed here, we're not waiting for SHM to move! */
541 return;
542 case MESSAGE_DISCARD_STATE:
543 /* odd, we're already in the start state... */
544 continue;
545 default:
546 LOG ("Received invalid messag %d\n", (int) code);
547 /* error, unexpected message */
548 return;
549 }
550 } 522 }
523 switch (code)
524 {
525 case MESSAGE_INIT_STATE:
526 if (0 != handle_init_message (pc))
527 {
528 LOG ("Failure to handle INIT\n");
529 return;
530 }
531 break;
532 case MESSAGE_EXTRACT_START:
533 if (0 != handle_start_message (pc))
534 {
535 LOG ("Failure to handle START\n");
536 return;
537 }
538 break;
539 case MESSAGE_UPDATED_SHM:
540 LOG ("Illegal message\n");
541 /* not allowed here, we're not waiting for SHM to move! */
542 return;
543 case MESSAGE_DISCARD_STATE:
544 /* odd, we're already in the start state... */
545 continue;
546 default:
547 LOG ("Received invalid messag %d\n", (int) code);
548 /* error, unexpected message */
549 return;
550 }
551 }
551} 552}
552 553
553 554
@@ -560,7 +561,7 @@ process_requests (struct ProcessingContext *pc)
560 */ 561 */
561static void 562static void
562open_dev_null (int target_fd, 563open_dev_null (int target_fd,
563 int flags) 564 int flags)
564{ 565{
565 int fd; 566 int fd;
566 567
@@ -570,10 +571,10 @@ open_dev_null (int target_fd,
570 fd = open ("\\\\?\\NUL", flags); 571 fd = open ("\\\\?\\NUL", flags);
571#endif 572#endif
572 if (-1 == fd) 573 if (-1 == fd)
573 { 574 {
574 LOG_STRERROR_FILE ("open", "/dev/null"); 575 LOG_STRERROR_FILE ("open", "/dev/null");
575 return; /* good luck */ 576 return; /* good luck */
576 } 577 }
577 if (fd == target_fd) 578 if (fd == target_fd)
578 return; /* already done */ 579 return; /* already done */
579 if (-1 == dup2 (fd, target_fd)) 580 if (-1 == dup2 (fd, target_fd))
@@ -598,32 +599,32 @@ open_dev_null (int target_fd,
598 */ 599 */
599void 600void
600EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, 601EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin,
601 int in, int out) 602 int in, int out)
602{ 603{
603 struct ProcessingContext pc; 604 struct ProcessingContext pc;
604 605
605 if (0 != EXTRACTOR_plugin_load_ (plugin)) 606 if (0 != EXTRACTOR_plugin_load_ (plugin))
606 { 607 {
607#if DEBUG 608#if DEBUG
608 fprintf (stderr, "Plugin `%s' failed to load!\n", 609 fprintf (stderr, "Plugin `%s' failed to load!\n",
609 plugin->short_libname); 610 plugin->short_libname);
610#endif 611#endif
611 return; 612 return;
612 } 613 }
613 if ( (NULL != plugin->specials) && 614 if ( (NULL != plugin->specials) &&
614 (NULL != strstr (plugin->specials, "close-stderr"))) 615 (NULL != strstr (plugin->specials, "close-stderr")))
615 { 616 {
616 if (0 != close (2)) 617 if (0 != close (2))
617 LOG_STRERROR ("close"); 618 LOG_STRERROR ("close");
618 open_dev_null (2, O_WRONLY); 619 open_dev_null (2, O_WRONLY);
619 } 620 }
620 if ( (NULL != plugin->specials) && 621 if ( (NULL != plugin->specials) &&
621 (NULL != strstr (plugin->specials, "close-stdout"))) 622 (NULL != strstr (plugin->specials, "close-stdout")))
622 { 623 {
623 if (0 != close (1)) 624 if (0 != close (1))
624 LOG_STRERROR ("close"); 625 LOG_STRERROR ("close");
625 open_dev_null (1, O_WRONLY); 626 open_dev_null (1, O_WRONLY);
626 } 627 }
627 pc.plugin = plugin; 628 pc.plugin = plugin;
628 pc.in = in; 629 pc.in = in;
629 pc.out = out; 630 pc.out = out;
@@ -643,10 +644,10 @@ EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin,
643 (((void*) 1) != pc.shm) ) 644 (((void*) 1) != pc.shm) )
644 munmap (pc.shm, pc.shm_map_size); 645 munmap (pc.shm, pc.shm_map_size);
645 if (-1 != pc.shm_id) 646 if (-1 != pc.shm_id)
646 { 647 {
647 if (0 != close (pc.shm_id)) 648 if (0 != close (pc.shm_id))
648 LOG_STRERROR ("close"); 649 LOG_STRERROR ("close");
649 } 650 }
650#endif 651#endif
651} 652}
652 653
@@ -668,43 +669,43 @@ read_plugin_data (int fd)
668 669
669 // FIXME: check for errors from 'EXTRACTOR_read_all_'! 670 // FIXME: check for errors from 'EXTRACTOR_read_all_'!
670 if (NULL == (ret = malloc (sizeof (struct EXTRACTOR_PluginList)))) 671 if (NULL == (ret = malloc (sizeof (struct EXTRACTOR_PluginList))))
671 { 672 {
672 LOG_STRERROR ("malloc"); 673 LOG_STRERROR ("malloc");
673 return NULL; 674 return NULL;
674 } 675 }
675 memset (ret, 0, sizeof (struct EXTRACTOR_PluginList)); 676 memset (ret, 0, sizeof (struct EXTRACTOR_PluginList));
676 /*GetSystemInfo (&si); 677 /*GetSystemInfo (&si);
677 ret->allocation_granularity = si.dwAllocationGranularity;*/ 678 ret->allocation_granularity = si.dwAllocationGranularity;*/
678 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); 679 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t));
679 if (NULL == (ret->libname = malloc (i))) 680 if (NULL == (ret->libname = malloc (i)))
680 { 681 {
681 free (ret); 682 free (ret);
682 return NULL; 683 return NULL;
683 } 684 }
684 EXTRACTOR_read_all_ (fd, ret->libname, i); 685 EXTRACTOR_read_all_ (fd, ret->libname, i);
685 ret->libname[i - 1] = '\0'; 686 ret->libname[i - 1] = '\0';
686 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); 687 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t));
687 if (NULL == (ret->short_libname = malloc (i))) 688 if (NULL == (ret->short_libname = malloc (i)))
688 { 689 {
689 free (ret->libname); 690 free (ret->libname);
690 free (ret); 691 free (ret);
691 return NULL; 692 return NULL;
692 } 693 }
693 EXTRACTOR_read_all_ (fd, ret->short_libname, i); 694 EXTRACTOR_read_all_ (fd, ret->short_libname, i);
694 ret->short_libname[i - 1] = '\0'; 695 ret->short_libname[i - 1] = '\0';
695 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); 696 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t));
696 if (0 == i) 697 if (0 == i)
697 { 698 {
698 ret->plugin_options = NULL; 699 ret->plugin_options = NULL;
699 return ret; 700 return ret;
700 } 701 }
701 if (NULL == (ret->plugin_options = malloc (i))) 702 if (NULL == (ret->plugin_options = malloc (i)))
702 { 703 {
703 free (ret->short_libname); 704 free (ret->short_libname);
704 free (ret->libname); 705 free (ret->libname);
705 free (ret); 706 free (ret);
706 return NULL; 707 return NULL;
707 } 708 }
708 EXTRACTOR_read_all_ (fd, ret->plugin_options, i); 709 EXTRACTOR_read_all_ (fd, ret->plugin_options, i);
709 ret->plugin_options[i - 1] = '\0'; 710 ret->plugin_options[i - 1] = '\0';
710 return ret; 711 return ret;
@@ -716,9 +717,9 @@ read_plugin_data (int fd)
716 */ 717 */
717void CALLBACK 718void CALLBACK
718RundllEntryPoint (HWND hwnd, 719RundllEntryPoint (HWND hwnd,
719 HINSTANCE hinst, 720 HINSTANCE hinst,
720 LPSTR lpszCmdLine, 721 LPSTR lpszCmdLine,
721 int nCmdShow) 722 int nCmdShow)
722{ 723{
723 struct EXTRACTOR_PluginList *plugin; 724 struct EXTRACTOR_PluginList *plugin;
724 intptr_t in_h; 725 intptr_t in_h;
@@ -732,11 +733,11 @@ RundllEntryPoint (HWND hwnd,
732 setmode (in, _O_BINARY); 733 setmode (in, _O_BINARY);
733 setmode (out, _O_BINARY); 734 setmode (out, _O_BINARY);
734 if (NULL == (plugin = read_plugin_data (in))) 735 if (NULL == (plugin = read_plugin_data (in)))
735 { 736 {
736 close (in); 737 close (in);
737 close (out); 738 close (out);
738 return; 739 return;
739 } 740 }
740 EXTRACTOR_plugin_main_ (plugin, in, out); 741 EXTRACTOR_plugin_main_ (plugin, in, out);
741 close (in); 742 close (in);
742 close (out); 743 close (out);
@@ -745,8 +746,7 @@ RundllEntryPoint (HWND hwnd,
745 * called by the OS) or call FreeLibrary() on it directly or 746 * called by the OS) or call FreeLibrary() on it directly or
746 * indirectly. 747 * indirectly.
747 * By terminating here we alleviate that problem. 748 * By terminating here we alleviate that problem.
748 */ 749 */TerminateProcess (GetCurrentProcess (), 0);
749 TerminateProcess (GetCurrentProcess (), 0);
750} 750}
751 751
752 752
@@ -755,9 +755,9 @@ RundllEntryPoint (HWND hwnd,
755 */ 755 */
756void CALLBACK 756void CALLBACK
757RundllEntryPointA (HWND hwnd, 757RundllEntryPointA (HWND hwnd,
758 HINSTANCE hinst, 758 HINSTANCE hinst,
759 LPSTR lpszCmdLine, 759 LPSTR lpszCmdLine,
760 int nCmdShow) 760 int nCmdShow)
761{ 761{
762 return RundllEntryPoint (hwnd, hinst, lpszCmdLine, nCmdShow); 762 return RundllEntryPoint (hwnd, hinst, lpszCmdLine, nCmdShow);
763} 763}