bb6091 - check lseek() return

pull/1/head
Shawn Webb 13 years ago
parent 5fc6e404ae
commit 9691454612
  1. 12
      libclamav/autoit.c
  2. 24
      libclamav/binhex.c
  3. 6
      libclamav/bytecode.c
  4. 5
      libclamav/bytecode_api.c
  5. 13
      libclamav/ishield.c
  6. 6
      libclamav/nsis/nulsft.c
  7. 5
      libclamav/ole2_extract.c
  8. 9
      libclamav/pe.c
  9. 18
      libclamav/scanners.c

@ -379,7 +379,11 @@ static int ea05(cli_ctx *ctx, const uint8_t *base, char *tmpd) {
cli_dbgmsg("autoit: file extracted to %s\n", tempfile);
else
cli_dbgmsg("autoit: file successfully extracted\n");
lseek(i, 0, SEEK_SET);
if (lseek(i, 0, SEEK_SET) == -1) {
cli_dbgmsg("autoit: call to lseek() has failed\n");
close(i);
return CL_ESEEK;
}
if(cli_magic_scandesc(i, ctx) == CL_VIRUS) {
close(i);
if(!ctx->engine->keeptmp)
@ -896,7 +900,11 @@ static int ea06(cli_ctx *ctx, const uint8_t *base, char *tmpd) {
cli_dbgmsg("autoit: %s extracted to %s\n", (script)?"script":"file", tempfile);
else
cli_dbgmsg("autoit: %s successfully extracted\n", (script)?"script":"file");
lseek(i, 0, SEEK_SET);
if (lseek(i, 0, SEEK_SET) == -1) {
cli_dbgmsg("autoit: call to lseek() has failed\n");
close(i);
return CL_ESEEK;
}
if(cli_magic_scandesc(i, ctx) == CL_VIRUS) {
close(i);
if(!ctx->engine->keeptmp)

@ -109,7 +109,11 @@ int cli_binhex(cli_ctx *ctx) {
}
if(!datalen) {
write_phase++;
lseek(datafd, 0, SEEK_SET);
if (lseek(datafd, 0, SEEK_SET) == -1) {
cli_dbgmsg("cli_binhex: call to lseek() has failed\n");
ret = CL_ESEEK;
break;
}
ret = cli_magic_scandesc(datafd, ctx);
if(ret == CL_VIRUS) break;
}
@ -151,7 +155,11 @@ int cli_binhex(cli_ctx *ctx) {
break;
}
if(!reslen) {
lseek(resfd, 0, SEEK_SET);
if (lseek(resfd, 0, SEEK_SET) == -1) {
cli_dbgmsg("cli_binhex: call to lseek() has failed\n");
ret = CL_ESEEK;
break;
}
ret = cli_magic_scandesc(resfd, ctx);
break;
}
@ -159,11 +167,19 @@ int cli_binhex(cli_ctx *ctx) {
if(!enc_todo) {
if(write_phase == IN_DATA) {
cli_dbgmsg("cli_binhex: scanning partially extracted data fork\n");
lseek(datafd, 0, SEEK_SET);
if (lseek(datafd, 0, SEEK_SET) == -1) {
cli_dbgmsg("cli_binhex: call to lseek() has failed\n");
ret = CL_ESEEK;
break;
}
ret = cli_magic_scandesc(datafd, ctx);
} else if(write_phase == IN_RES) {
cli_dbgmsg("cli_binhex: scanning partially extracted resource fork\n");
lseek(resfd, 0, SEEK_SET);
if (lseek(resfd, 0, SEEK_SET) == -1) {
cli_dbgmsg("cli_binhex: call to lseek() has failed\n");
ret = CL_ESEEK;
break;
}
ret = cli_magic_scandesc(resfd, ctx);
}
break;

@ -161,8 +161,10 @@ static int cli_bytecode_context_reset(struct cli_bc_ctx *ctx)
if(fd >= 0) {
ret = cli_scandesc(fd, cctx, CL_TYPE_HTML, 0, NULL, AC_SCAN_VIR, NULL);
if (ret == CL_CLEAN) {
lseek(fd, 0, SEEK_SET);
ret = cli_scandesc(fd, cctx, CL_TYPE_TEXT_ASCII, 0, NULL, AC_SCAN_VIR, NULL);
if (lseek(fd, 0, SEEK_SET) == -1)
cli_dbgmsg("cli_bytecode: call to lseek() has failed\n");
else
ret = cli_scandesc(fd, cctx, CL_TYPE_TEXT_ASCII, 0, NULL, AC_SCAN_VIR, NULL);
}
close(fd);
}

@ -502,7 +502,10 @@ int32_t cli_bcapi_extract_new(struct cli_bc_ctx *ctx, int32_t id)
if (ctx->ctx && cli_updatelimits(ctx->ctx, ctx->written))
return -1;
ctx->written = 0;
lseek(ctx->outfd, 0, SEEK_SET);
if (lseek(ctx->outfd, 0, SEEK_SET) == -1) {
cli_dbgmsg("bytecode: call to lseek() has failed\n");
return CL_ESEEK;
}
cli_dbgmsg("bytecode: scanning extracted file %s\n", ctx->tempfile);
cctx = (cli_ctx*)ctx->ctx;
if (cctx) {

@ -298,7 +298,10 @@ int cli_scanishield_msi(cli_ctx *ctx, off_t off) {
if (ret == CL_SUCCESS) {
cli_dbgmsg("ishield-msi: extracted to %s\n", tempfile);
lseek(ofd, 0, SEEK_SET);
if (lseek(ofd, 0, SEEK_SET) == -1) {
cli_dbgmsg("ishield-msi: call to lseek() failed\n");
ret = CL_ESEEK;
}
ret = cli_magic_scandesc(ofd, ctx);
}
close(ofd);
@ -470,7 +473,10 @@ static int is_dump_and_scan(cli_ctx *ctx, off_t off, size_t fsize) {
}
if(!fsize) {
cli_dbgmsg("ishield: extracted to %s\n", fname);
lseek(ofd, 0, SEEK_SET);
if (lseek(ofd, 0, SEEK_SET) == -1) {
cli_dbgmsg("ishield: call to lseek() failed\n");
ret = CL_ESEEK;
}
ret = cli_magic_scandesc(ofd, ctx);
}
close(ofd);
@ -766,7 +772,8 @@ static int is_extract_cab(cli_ctx *ctx, uint64_t off, uint64_t size, uint64_t cs
cli_dbgmsg("is_extract_cab: extracted %llu bytes to %s, expected %llu, scanning anyway.\n", (long long)outsz, tempfile, (long long)size);
else
cli_dbgmsg("is_extract_cab: extracted to %s\n", tempfile);
lseek(ofd, 0, SEEK_SET);
if (lseek(ofd, 0, SEEK_SET) == -1)
cli_dbgmsg("is_extract_cab: call to lseek() failed\n");
ret = cli_magic_scandesc(ofd, ctx);
}

@ -512,7 +512,11 @@ int cli_scannulsft(cli_ctx *ctx, off_t offset) {
ret = cli_nsis_unpack(&nsist, ctx);
if (ret == CL_SUCCESS) {
cli_dbgmsg("NSIS: Successully extracted file #%u\n", nsist.fno);
lseek(nsist.ofd, 0, SEEK_SET);
if (lseek(nsist.ofd, 0, SEEK_SET) == -1) {
cli_dbgmsg("NSIS: call to lseek() failed\n");
free(nsist.dir);
return CL_ESEEK;
}
if(nsist.fno == 1)
ret=cli_scandesc(nsist.ofd, ctx, 0, 0, NULL, AC_SCAN_VIR, NULL);
else

@ -788,7 +788,10 @@ static int handler_otf(ole2_header_t *hdr, property_t *prop, const char *dir, cl
}
}
lseek(ofd, 0, SEEK_SET);
if (lseek(ofd, 0, SEEK_SET) == -1) {
return CL_ESEEK;
}
ret=cli_magic_scandesc(ofd, ctx);
close(ofd);
free(buff);

@ -1951,7 +1951,14 @@ int cli_scanpe(cli_ctx *ctx)
}
free(dest);
lseek(ndesc, 0, SEEK_SET);
if (lseek(ndesc, 0, SEEK_SET) == -1) {
cli_dbgmsg("UPX/FSG: lseek() failed\n");
close(ndesc);
CLI_TMPUNLK();
free(tempfile);
SHA_RESET;
return CL_ESEEK;
}
if(ctx->engine->keeptmp)
cli_dbgmsg("UPX/FSG: Decompressed data saved in %s\n", tempfile);

@ -247,7 +247,10 @@ static int cli_scanrar(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
if(ret == UNRAR_PASSWD) {
cli_dbgmsg("RAR: Encrypted main header\n");
if(DETECT_ENCRYPTED) {
lseek(desc, 0, SEEK_SET);
if (lseek(desc, 0, SEEK_SET) == -1) {
cli_dbgmsg("RAR: call to lseek() failed\n");
return CL_ESEEK;
}
ret = cli_scandesc(desc, ctx, 0, 0, NULL, AC_SCAN_VIR, NULL);
if(ret != CL_VIRUS)
cli_append_virus(ctx, "Heuristics.Encrypted.RAR");
@ -294,7 +297,10 @@ static int cli_scanrar(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
ret = CL_EFORMAT;
if(rar_state.ofd > 0) {
lseek(rar_state.ofd,0,SEEK_SET);
if (lseek(rar_state.ofd,0,SEEK_SET) == -1) {
cli_dbgmsg("RAR: Call to lseek() failed\n");
ret = CL_ESEEK;
}
rc = cli_magic_scandesc(rar_state.ofd,ctx);
close(rar_state.ofd);
if(!ctx->engine->keeptmp)
@ -396,7 +402,9 @@ static int cli_scanarj(cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_check)
cli_dbgmsg("ARJ: cli_unarj_extract_file Error: %s\n", cl_strerror(ret));
}
if (metadata.ofd >= 0) {
lseek(metadata.ofd, 0, SEEK_SET);
if (lseek(metadata.ofd, 0, SEEK_SET) == -1) {
cli_dbgmsg("ARJ: call to lseek() failed\n");
}
rc = cli_magic_scandesc(metadata.ofd, ctx);
close(metadata.ofd);
if (rc == CL_VIRUS) {
@ -2409,7 +2417,9 @@ static int magic_scandesc(cli_ctx *ctx, cli_file_t type)
}
}
} while (len > 0);
lseek(desc, 0, SEEK_SET);
if (lseek(desc, 0, SEEK_SET) == -1) {
cli_dbgmsg("magic_scandesc: call to lseek() failed\n");
}
}
ret = cli_scanrar(desc, ctx, 0, NULL);
if (tmpname) {

Loading…
Cancel
Save