improve I/O error handling in cli_filetype2 (bb#818)

git-svn: trunk@3605
This commit is contained in:
Tomasz Kojm
2008-02-11 10:21:03 +00:00
parent e1bb690579
commit 7db77fbf36
3 changed files with 14 additions and 3 deletions

View File

@@ -1,3 +1,7 @@
Mon Feb 11 11:09:10 CET 2008 (tk)
---------------------------------
* libclamav/filetypes.c: improve I/O error handling in cli_filetype2 (bb#818)
Sun Feb 10 10:28:55 EET 2008 (edwin)
------------------------------------
* configure, configure.in: don't use EXIT_SUCCESS if <stdlib.h> is not

View File

@@ -149,8 +149,11 @@ cli_file_t cli_filetype2(int desc, const struct cl_engine *engine)
}
memset(smallbuff, 0, sizeof(smallbuff));
if((bread = read(desc, smallbuff, MAGIC_BUFFER_SIZE)) > 0)
ret = cli_filetype(smallbuff, bread, engine);
bread = cli_readn(desc, smallbuff, MAGIC_BUFFER_SIZE);
if(bread == -1)
return CL_TYPE_ERROR;
ret = cli_filetype(smallbuff, bread, engine);
if(ret >= CL_TYPE_TEXT_ASCII && ret <= CL_TYPE_BINARY_DATA) {
/* 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)
return ret;
lseek(desc, 0, SEEK_SET);
if((bread = read(desc, bigbuff, 37638)) > 0) {
if((bread = cli_readn(desc, bigbuff, 37638)) > 0) {
bigbuff[bread] = 0;

View File

@@ -1838,6 +1838,10 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
lseek(desc, 0, SEEK_SET);
type = cli_filetype2(desc, ctx->engine);
if(type == CL_TYPE_ERROR) {
cli_dbgmsg("cli_magic_scandesc: cli_filetype2 returned CL_TYPE_ERROR\n");
return CL_EIO;
}
lseek(desc, 0, SEEK_SET);
if(type != CL_TYPE_IGNORED && ctx->engine->sdb) {