Browse code

libclamav: fix error reporting for BinHex files (bb#1685)

Tomasz Kojm authored on 2010/01/04 23:35:52
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Jan  4 15:35:16 CET 2010 (tk)
2
+---------------------------------
3
+ * libclamav: fix error reporting for BinHex files (bb#1685)
4
+
1 5
 Wed Dec 30 00:19:21 CET 2009 (tk)
2 6
 ---------------------------------
3 7
  * libclamav: add support for FileSize, EntryPoint and NumberOfSections in
... ...
@@ -120,6 +120,7 @@ cli_binhex(const char *dir, fmap_t *map)
120 120
 	long bytesleft;
121 121
 	message *m;
122 122
 	fileblob *fb;
123
+	text *t_line;
123 124
 
124 125
 	size = (size_t)map->len;
125 126
 
... ...
@@ -179,12 +180,20 @@ cli_binhex(const char *dir, fmap_t *map)
179 179
 	if(line)
180 180
 		free(line);
181 181
 
182
-	if(binhexBegin(m) == NULL) {
182
+	if((t_line = binhexBegin(m)) == NULL) {
183 183
 		messageDestroy(m);
184 184
 		cli_dbgmsg("No binhex line found\n");
185 185
 		return CL_EFORMAT;
186 186
 	}
187 187
 
188
+	while(((t_line = t_line->t_next) != NULL) && (t_line->t_line == NULL));
189
+
190
+	if(!t_line) {
191
+		messageDestroy(m);
192
+		cli_dbgmsg("No binhex data to parse\n");
193
+		return CL_EFORMAT;
194
+	}
195
+
188 196
 	/* similar to binhexMessage */
189 197
 	messageSetEncoding(m, "x-binhex");
190 198
 
... ...
@@ -199,5 +208,6 @@ cli_binhex(const char *dir, fmap_t *map)
199 199
 	if(fb)
200 200
 		return CL_CLEAN;	/* a lie - but it gets things going */
201 201
 	/* return CL_EIO; */	/* probably CL_EMEM, but we can't tell at this layer */
202
-	return CL_EMEM;
202
+	/* TK: CL_EMEM is too generic here and should not be reported for parsing errors */
203
+	return CL_EFORMAT;
203 204
 }
... ...
@@ -1212,6 +1212,12 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1212 1212
 		      (t_line->t_line == NULL))
1213 1213
 			;
1214 1214
 
1215
+		if(!t_line) {
1216
+			cli_warnmsg("No binhex data to parse\n");
1217
+			(*destroy)(ret);
1218
+			return NULL;
1219
+		}
1220
+
1215 1221
 		tmp = textToBlob(t_line, NULL,
1216 1222
 			((m->numberOfEncTypes == 1) && (m->encodingTypes[0] == BINHEX)) ? destroy_text : 0);
1217 1223