git-svn: trunk@3605
Tomasz Kojm authored on 2008/02/11 19:21:03... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Mon Feb 11 11:09:10 CET 2008 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav/filetypes.c: improve I/O error handling in cli_filetype2 (bb#818) |
|
4 |
+ |
|
1 | 5 |
Sun Feb 10 10:28:55 EET 2008 (edwin) |
2 | 6 |
------------------------------------ |
3 | 7 |
* configure, configure.in: don't use EXIT_SUCCESS if <stdlib.h> is not |
... | ... |
@@ -149,8 +149,11 @@ cli_file_t cli_filetype2(int desc, const struct cl_engine *engine) |
149 | 149 |
} |
150 | 150 |
|
151 | 151 |
memset(smallbuff, 0, sizeof(smallbuff)); |
152 |
- if((bread = read(desc, smallbuff, MAGIC_BUFFER_SIZE)) > 0) |
|
153 |
- ret = cli_filetype(smallbuff, bread, engine); |
|
152 |
+ bread = cli_readn(desc, smallbuff, MAGIC_BUFFER_SIZE); |
|
153 |
+ if(bread == -1) |
|
154 |
+ return CL_TYPE_ERROR; |
|
155 |
+ |
|
156 |
+ ret = cli_filetype(smallbuff, bread, engine); |
|
154 | 157 |
|
155 | 158 |
if(ret >= CL_TYPE_TEXT_ASCII && ret <= CL_TYPE_BINARY_DATA) { |
156 | 159 |
/* HTML files may contain special characters and could be |
... | ... |
@@ -230,7 +233,7 @@ cli_file_t cli_filetype2(int desc, const struct cl_engine *engine) |
230 | 230 |
return ret; |
231 | 231 |
|
232 | 232 |
lseek(desc, 0, SEEK_SET); |
233 |
- if((bread = read(desc, bigbuff, 37638)) > 0) { |
|
233 |
+ if((bread = cli_readn(desc, bigbuff, 37638)) > 0) { |
|
234 | 234 |
|
235 | 235 |
bigbuff[bread] = 0; |
236 | 236 |
|
... | ... |
@@ -1838,6 +1838,10 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx) |
1838 | 1838 |
|
1839 | 1839 |
lseek(desc, 0, SEEK_SET); |
1840 | 1840 |
type = cli_filetype2(desc, ctx->engine); |
1841 |
+ if(type == CL_TYPE_ERROR) { |
|
1842 |
+ cli_dbgmsg("cli_magic_scandesc: cli_filetype2 returned CL_TYPE_ERROR\n"); |
|
1843 |
+ return CL_EIO; |
|
1844 |
+ } |
|
1841 | 1845 |
lseek(desc, 0, SEEK_SET); |
1842 | 1846 |
|
1843 | 1847 |
if(type != CL_TYPE_IGNORED && ctx->engine->sdb) { |