git-svn: trunk@1116
Nigel Horne authored on 2004/11/23 00:16:53... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: binhex.c,v $ |
20 |
+ * Revision 1.6 2004/11/22 15:16:53 nigelhorne |
|
21 |
+ * Use cli_realloc instead of many cli_mallocs |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.5 2004/11/18 20:11:34 nigelhorne |
21 | 24 |
* Fix segfault |
22 | 25 |
* |
... | ... |
@@ -30,7 +33,7 @@ |
30 | 30 |
* First draft of binhex.c |
31 | 31 |
* |
32 | 32 |
*/ |
33 |
-static char const rcsid[] = "$Id: binhex.c,v 1.5 2004/11/18 20:11:34 nigelhorne Exp $"; |
|
33 |
+static char const rcsid[] = "$Id: binhex.c,v 1.6 2004/11/22 15:16:53 nigelhorne Exp $"; |
|
34 | 34 |
|
35 | 35 |
#include "clamav.h" |
36 | 36 |
|
... | ... |
@@ -71,7 +74,7 @@ int |
71 | 71 |
cli_binhex(const char *dir, int desc) |
72 | 72 |
{ |
73 | 73 |
struct stat statb; |
74 |
- char *buf, *start; |
|
74 |
+ char *buf, *start, *line; |
|
75 | 75 |
size_t size, bytesleft; |
76 | 76 |
message *m; |
77 | 77 |
fileblob *fb; |
... | ... |
@@ -95,10 +98,11 @@ cli_binhex(const char *dir, int desc) |
95 | 95 |
cli_dbgmsg("mmap'ed binhex file\n"); |
96 | 96 |
|
97 | 97 |
bytesleft = size; |
98 |
+ line = NULL; |
|
98 | 99 |
|
99 | 100 |
while(bytesleft) { |
100 | 101 |
int length = 0; |
101 |
- char *ptr, *line; |
|
102 |
+ char *ptr; |
|
102 | 103 |
|
103 | 104 |
/* printf("%d: ", bytesleft); */ |
104 | 105 |
|
... | ... |
@@ -109,7 +113,7 @@ cli_binhex(const char *dir, int desc) |
109 | 109 |
|
110 | 110 |
/* printf("%d: ", length); */ |
111 | 111 |
|
112 |
- line = cli_malloc(length + 1); |
|
112 |
+ line = cli_realloc(line, length + 1); |
|
113 | 113 |
|
114 | 114 |
memcpy(line, buf, length); |
115 | 115 |
line[length] = '\0'; |
... | ... |
@@ -119,14 +123,15 @@ cli_binhex(const char *dir, int desc) |
119 | 119 |
if(messageAddStr(m, line) < 0) |
120 | 120 |
break; |
121 | 121 |
|
122 |
- free(line); |
|
123 |
- |
|
124 | 122 |
buf = ++ptr; |
125 | 123 |
bytesleft--; |
126 | 124 |
} |
127 | 125 |
munmap(start, size); |
128 | 126 |
|
129 |
- if(m->binhex == NULL) { |
|
127 |
+ if(line) |
|
128 |
+ free(line); |
|
129 |
+ |
|
130 |
+ if(binhexBegin(m) == NULL) { |
|
130 | 131 |
messageDestroy(m); |
131 | 132 |
cli_errmsg("No binhex line found\n"); |
132 | 133 |
return CL_EFORMAT; |