git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1137 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2004/11/28 06:56:41... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Sat Nov 27 21:55:45 GMT 2004 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/mbox.c: Changed some more strtok to cli_strtok |
|
4 |
+ |
|
1 | 5 |
Sat Nov 27 19:53:33 CET 2004 (tk) |
2 | 6 |
--------------------------------- |
3 | 7 |
* libclamav/scanners.c: cli_scanrar: skip splitted files (patch by Andrey J. |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: mbox.c,v $ |
20 |
+ * Revision 1.191 2004/11/27 21:55:06 nigelhorne |
|
21 |
+ * Changed some more strtok to cli_strtok |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.190 2004/11/27 14:49:13 nigelhorne |
21 | 24 |
* Use a static array for the partial directory |
22 | 25 |
* |
... | ... |
@@ -558,7 +561,7 @@ |
558 | 558 |
* Compilable under SCO; removed duplicate code with message.c |
559 | 559 |
* |
560 | 560 |
*/ |
561 |
-static char const rcsid[] = "$Id: mbox.c,v 1.190 2004/11/27 14:49:13 nigelhorne Exp $"; |
|
561 |
+static char const rcsid[] = "$Id: mbox.c,v 1.191 2004/11/27 21:55:06 nigelhorne Exp $"; |
|
562 | 562 |
|
563 | 563 |
#if HAVE_CONFIG_H |
564 | 564 |
#include "clamav-config.h" |
... | ... |
@@ -1683,7 +1686,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t |
1683 | 1683 |
* RFC1521, unrecognised multiparts |
1684 | 1684 |
* should be treated as multipart/mixed. |
1685 | 1685 |
*/ |
1686 |
- cli_warnmsg("Unsupported multipart format `%s', parsed as mixed\n", mimeSubtype); |
|
1686 |
+ cli_dbgmsg("Unsupported multipart format `%s', parsed as mixed\n", mimeSubtype); |
|
1687 | 1687 |
mimeSubtype = "mixed"; |
1688 | 1688 |
break; |
1689 | 1689 |
} |
... | ... |
@@ -2612,28 +2615,25 @@ continuationMarker(const char *line) |
2612 | 2612 |
static int |
2613 | 2613 |
parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const char *arg) |
2614 | 2614 |
{ |
2615 |
-#ifdef CL_THREAD_SAFE |
|
2616 |
- char *strptr; |
|
2617 |
-#endif |
|
2618 |
- char *copy, *ptr; |
|
2615 |
+ char *copy, *p; |
|
2616 |
+ const char *ptr; |
|
2619 | 2617 |
int commandNumber; |
2620 | 2618 |
|
2621 | 2619 |
cli_dbgmsg("parseMimeHeader: cmd='%s', arg='%s'\n", cmd, arg); |
2622 | 2620 |
|
2623 |
- ptr = rfc822comments(cmd); |
|
2624 |
- if(ptr) { |
|
2625 |
- commandNumber = tableFind(rfc821Table, ptr); |
|
2626 |
- free(ptr); |
|
2621 |
+ copy = rfc822comments(cmd); |
|
2622 |
+ if(copy) { |
|
2623 |
+ commandNumber = tableFind(rfc821Table, copy); |
|
2624 |
+ free(copy); |
|
2627 | 2625 |
} else |
2628 | 2626 |
commandNumber = tableFind(rfc821Table, cmd); |
2629 | 2627 |
|
2630 | 2628 |
copy = rfc822comments(arg); |
2631 |
- if(copy == NULL) |
|
2632 |
- copy = strdup(arg); |
|
2633 |
- if(copy == NULL) |
|
2634 |
- return -1; |
|
2635 | 2629 |
|
2636 |
- ptr = copy; |
|
2630 |
+ if(copy) |
|
2631 |
+ ptr = copy; |
|
2632 |
+ else |
|
2633 |
+ ptr = arg; |
|
2637 | 2634 |
|
2638 | 2635 |
switch(commandNumber) { |
2639 | 2636 |
case CONTENT_TYPE: |
... | ... |
@@ -2654,14 +2654,14 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c |
2654 | 2654 |
* email client writers don't get it right |
2655 | 2655 |
*/ |
2656 | 2656 |
cli_warnmsg("Empty content-type received, no subtype specified, assuming text/plain; charset=us-ascii\n"); |
2657 |
- else if(strchr(copy, '/') == NULL) |
|
2657 |
+ else if(strchr(ptr, '/') == NULL) |
|
2658 | 2658 |
/* |
2659 | 2659 |
* Empty field, such as |
2660 | 2660 |
* Content-Type: |
2661 | 2661 |
* which I believe is illegal according to |
2662 | 2662 |
* RFC1521 |
2663 | 2663 |
*/ |
2664 |
- cli_dbgmsg("Invalid content-type '%s' received, no subtype specified, assuming text/plain; charset=us-ascii\n", copy); |
|
2664 |
+ cli_dbgmsg("Invalid content-type '%s' received, no subtype specified, assuming text/plain; charset=us-ascii\n", ptr); |
|
2665 | 2665 |
else { |
2666 | 2666 |
int i; |
2667 | 2667 |
char *mimeArgs; /* RHS of the ; */ |
... | ... |
@@ -2682,16 +2682,19 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c |
2682 | 2682 |
* the quotes, it doesn't handle |
2683 | 2683 |
* them properly |
2684 | 2684 |
*/ |
2685 |
- while(isspace(*copy)) |
|
2686 |
- copy++; |
|
2687 |
- if(copy[0] == '\"') |
|
2688 |
- copy++; |
|
2685 |
+ while(isspace(*ptr)) |
|
2686 |
+ ptr++; |
|
2687 |
+ if(ptr[0] == '\"') |
|
2688 |
+ ptr++; |
|
2689 | 2689 |
|
2690 |
- if(copy[0] != '/') { |
|
2690 |
+ if(ptr[0] != '/') { |
|
2691 | 2691 |
char *s; |
2692 | 2692 |
char *mimeType; /* LHS of the ; */ |
2693 |
+#ifdef CL_THREAD_SAFE |
|
2694 |
+ char *strptr; |
|
2695 |
+#endif |
|
2693 | 2696 |
|
2694 |
- s = mimeType = cli_strtok(copy, 0, ";"); |
|
2697 |
+ s = mimeType = cli_strtok(ptr, 0, ";"); |
|
2695 | 2698 |
/* |
2696 | 2699 |
* Handle |
2697 | 2700 |
* Content-Type: foo/bar multipart/mixed |
... | ... |
@@ -2753,7 +2756,7 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c |
2753 | 2753 |
* we find the boundary argument set it |
2754 | 2754 |
*/ |
2755 | 2755 |
i = 1; |
2756 |
- while((mimeArgs = cli_strtok(copy, i++, ";")) != NULL) { |
|
2756 |
+ while((mimeArgs = cli_strtok(ptr, i++, ";")) != NULL) { |
|
2757 | 2757 |
cli_dbgmsg("mimeArgs = '%s'\n", mimeArgs); |
2758 | 2758 |
|
2759 | 2759 |
messageAddArguments(m, mimeArgs); |
... | ... |
@@ -2762,24 +2765,22 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c |
2762 | 2762 |
} |
2763 | 2763 |
break; |
2764 | 2764 |
case CONTENT_TRANSFER_ENCODING: |
2765 |
- messageSetEncoding(m, copy); |
|
2765 |
+ messageSetEncoding(m, ptr); |
|
2766 | 2766 |
break; |
2767 | 2767 |
case CONTENT_DISPOSITION: |
2768 |
-#ifdef CL_THREAD_SAFE |
|
2769 |
- arg = strtok_r(copy, ";", &strptr); |
|
2770 |
- if(arg && *arg) { |
|
2771 |
- messageSetDispositionType(m, arg); |
|
2772 |
- messageAddArgument(m, strtok_r(NULL, "\r\n", &strptr)); |
|
2773 |
- } |
|
2774 |
-#else |
|
2775 |
- arg = strtok(copy, ";"); |
|
2776 |
- if(arg && *arg) { |
|
2777 |
- messageSetDispositionType(m, arg); |
|
2778 |
- messageAddArgument(m, strtok(NULL, "\r\n")); |
|
2768 |
+ p = cli_strtok(ptr, 0, ";"); |
|
2769 |
+ if(p) { |
|
2770 |
+ if(*p) { |
|
2771 |
+ messageSetDispositionType(m, p); |
|
2772 |
+ free(p); |
|
2773 |
+ p = cli_strtok(ptr, 1, ";"); |
|
2774 |
+ messageAddArgument(m, p); |
|
2775 |
+ } |
|
2776 |
+ free(p); |
|
2779 | 2777 |
} |
2780 |
-#endif |
|
2781 | 2778 |
} |
2782 |
- free(ptr); |
|
2779 |
+ if(copy) |
|
2780 |
+ free(copy); |
|
2783 | 2781 |
|
2784 | 2782 |
return 0; |
2785 | 2783 |
} |
... | ... |
@@ -3319,7 +3320,6 @@ getURL(void *a) |
3319 | 3319 |
getURL(struct arg *arg) |
3320 | 3320 |
#endif |
3321 | 3321 |
{ |
3322 |
- char *fout; |
|
3323 | 3322 |
CURL *curl; |
3324 | 3323 |
FILE *fp; |
3325 | 3324 |
struct curl_slist *headers; |
... | ... |
@@ -3331,6 +3331,7 @@ getURL(struct arg *arg) |
3331 | 3331 |
const char *url = arg->url; |
3332 | 3332 |
const char *dir = arg->dir; |
3333 | 3333 |
const char *filename = arg->filename; |
3334 |
+ char fout[NAME_MAX + 1]; |
|
3334 | 3335 |
|
3335 | 3336 |
#ifdef CL_THREAD_SAFE |
3336 | 3337 |
pthread_mutex_lock(&init_mutex); |
... | ... |
@@ -3358,34 +3359,24 @@ getURL(struct arg *arg) |
3358 | 3358 |
if(curl_easy_setopt(curl, CURLOPT_URL, url) != 0) |
3359 | 3359 |
return NULL; |
3360 | 3360 |
|
3361 |
- fout = cli_malloc(strlen(dir) + strlen(filename) + 2); |
|
3362 |
- |
|
3363 |
- if(fout == NULL) { |
|
3364 |
- curl_easy_cleanup(curl); |
|
3365 |
- return NULL; |
|
3366 |
- } |
|
3367 |
- |
|
3368 | 3361 |
snprintf(fout, NAME_MAX, "%s/%s", dir, filename); |
3369 | 3362 |
|
3370 | 3363 |
fp = fopen(fout, "w"); |
3371 | 3364 |
|
3372 | 3365 |
if(fp == NULL) { |
3373 | 3366 |
cli_errmsg("Can't open '%s' for writing", fout); |
3374 |
- free(fout); |
|
3375 | 3367 |
curl_easy_cleanup(curl); |
3376 | 3368 |
return NULL; |
3377 | 3369 |
} |
3378 | 3370 |
#ifdef CURLOPT_WRITEDATA |
3379 | 3371 |
if(curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp) != 0) { |
3380 | 3372 |
fclose(fp); |
3381 |
- free(fout); |
|
3382 | 3373 |
curl_easy_cleanup(curl); |
3383 | 3374 |
return NULL; |
3384 | 3375 |
} |
3385 | 3376 |
#else |
3386 | 3377 |
if(curl_easy_setopt(curl, CURLOPT_FILE, fp) != 0) { |
3387 | 3378 |
fclose(fp); |
3388 |
- free(fout); |
|
3389 | 3379 |
curl_easy_cleanup(curl); |
3390 | 3380 |
return NULL; |
3391 | 3381 |
} |
... | ... |
@@ -3432,15 +3423,12 @@ getURL(struct arg *arg) |
3432 | 3432 |
* https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=139559 |
3433 | 3433 |
*/ |
3434 | 3434 |
|
3435 |
- if(curl_easy_perform(curl) != CURLE_OK) { |
|
3435 |
+ if(curl_easy_perform(curl) != CURLE_OK) |
|
3436 | 3436 |
cli_warnmsg("URL %s failed to download\n", url); |
3437 |
- unlink(fout); |
|
3438 |
- } |
|
3439 | 3437 |
|
3440 | 3438 |
fclose(fp); |
3441 | 3439 |
curl_slist_free_all(headers); |
3442 | 3440 |
curl_easy_cleanup(curl); |
3443 |
- free(fout); |
|
3444 | 3441 |
|
3445 | 3442 |
return NULL; |
3446 | 3443 |
} |