git-svn: trunk@3575
Török Edvin authored on 2008/02/03 17:57:05... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Sun Feb 3 10:38:08 EET 2008 (edwin) |
|
2 |
+------------------------------------ |
|
3 |
+ * libclamav/entconv.c: don't leave return value uninitialized. (bb #808). |
|
4 |
+ |
|
1 | 5 |
Sat Feb 2 18:51:55 EET 2008 (edwin) |
2 | 6 |
----------------------------------- |
3 | 7 |
* libclamav/entconv.h: enum encodings was missing (bb #807) |
... | ... |
@@ -366,7 +366,7 @@ static int iconv(iconv_t iconv_struct,char **inbuf, size_t *inbytesleft, |
366 | 366 |
|
367 | 367 |
static inline const char* detect_encoding(const unsigned char* bom, uint8_t* bom_found, uint8_t* enc_width) |
368 | 368 |
{ |
369 |
- const char* encoding; |
|
369 |
+ const char* encoding = NULL; |
|
370 | 370 |
int has_bom = 0; |
371 | 371 |
uint8_t enc_bytes = 1; /* default is UTF8, which has a minimum of 1 bytes */ |
372 | 372 |
/* undecided 32-bit encodings are treated as ucs4, and |
... | ... |
@@ -473,11 +473,16 @@ static inline const char* detect_encoding(const unsigned char* bom, uint8_t* bom |
473 | 473 |
|
474 | 474 |
/* detects UTF-16(LE/BE), UCS-4(all 4 variants). |
475 | 475 |
* UTF-8 and simple ASCII are ignored, because we can process those as text */ |
476 |
-const char* encoding_detect_bom(const unsigned char* bom) |
|
476 |
+const char* encoding_detect_bom(const unsigned char* bom, const size_t length) |
|
477 | 477 |
{ |
478 | 478 |
uint8_t has_bom; |
479 | 479 |
uint8_t enc_width; |
480 |
- const char* encoding = detect_encoding(bom, &has_bom, &enc_width); |
|
480 |
+ const char* encoding; |
|
481 |
+ |
|
482 |
+ if(length < 4) { |
|
483 |
+ return NULL; |
|
484 |
+ } |
|
485 |
+ encoding = detect_encoding(bom, &has_bom, &enc_width); |
|
481 | 486 |
return enc_width > 1 ? encoding : NULL; |
482 | 487 |
} |
483 | 488 |
|
... | ... |
@@ -51,7 +51,7 @@ enum encodings {E_UCS4,E_UTF16,E_UCS4_1234,E_UCS4_4321,E_UCS4_2143,E_UCS4_3412,E |
51 | 51 |
|
52 | 52 |
unsigned char* u16_normalize_tobuffer(uint16_t u16, unsigned char* dst, size_t dst_size); |
53 | 53 |
const char* entity_norm(struct entity_conv* conv,const unsigned char* entity); |
54 |
-const char* encoding_detect_bom(const unsigned char* bom); |
|
54 |
+const char* encoding_detect_bom(const unsigned char* bom, const size_t length); |
|
55 | 55 |
int encoding_normalize_toascii(const m_area_t* in_m_area, const char* initial_encoding, m_area_t* out_m_area); |
56 | 56 |
|
57 | 57 |
#endif |
... | ... |
@@ -187,7 +187,7 @@ cli_file_t cli_filetype2(int desc, const struct cl_engine *engine) |
187 | 187 |
/* check if we can autodetect this encoding. |
188 | 188 |
* If we can't don't try to detect HTML sig, since |
189 | 189 |
* we just tried that above, and failed */ |
190 |
- if((encoding = encoding_detect_bom(smallbuff))) { |
|
190 |
+ if((encoding = encoding_detect_bom(smallbuff, bread))) { |
|
191 | 191 |
unsigned char decodedbuff[sizeof(smallbuff)*2]; |
192 | 192 |
m_area_t in_area, out_area; |
193 | 193 |
|