git-svn: trunk@3737
aCaB authored on 2008/03/25 04:18:07... | ... |
@@ -1,7 +1,11 @@ |
1 |
+Mon Mar 24 19:31:10 CET 2008 (acab) |
|
2 |
+----------------------------------- |
|
3 |
+ * libclamav/nsis: a cleaner approach to bb#844 and bb#888 |
|
4 |
+ |
|
1 | 5 |
Fri Mar 21 23:14:31 CET 2008 (acab) |
2 | 6 |
----------------------------------- |
3 | 7 |
* libclamav/nsis: only insists to unpack for LZMA |
4 |
- partially reverts r3705 - bb#8888 |
|
8 |
+ partially reverts r3705 - bb#888 |
|
5 | 9 |
|
6 | 10 |
Fri Mar 21 03:31:16 CET 2008 (acab) |
7 | 11 |
----------------------------------- |
... | ... |
@@ -155,7 +155,6 @@ static int nsis_decomp(struct nsis_st *n) { |
155 | 155 |
n->nsis.next_out = n->bz.next_out; |
156 | 156 |
break; |
157 | 157 |
case COMP_LZMA: |
158 |
- ret = CL_SUCCESS; /* unpack broken files too - bb#873 - only for lzma - bb#888 - if it breaks once more i'm reverting everything */ |
|
159 | 158 |
switch (cli_LzmaDecode(&n->lz, &n->nsis)) { |
160 | 159 |
case LZMA_RESULT_OK: |
161 | 160 |
ret = CL_SUCCESS; |
... | ... |
@@ -189,7 +188,7 @@ static int nsis_decomp(struct nsis_st *n) { |
189 | 189 |
static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { |
190 | 190 |
unsigned char *ibuf; |
191 | 191 |
uint32_t size, loops; |
192 |
- int ret; |
|
192 |
+ int ret, gotsome=0; |
|
193 | 193 |
unsigned char obuf[BUFSIZ]; |
194 | 194 |
|
195 | 195 |
if (n->eof) { |
... | ... |
@@ -275,10 +274,12 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { |
275 | 275 |
|
276 | 276 |
while ((ret=nsis_decomp(n))==CL_SUCCESS) { |
277 | 277 |
if ((size = n->nsis.next_out - obuf)) { |
278 |
+ gotsome=1; |
|
278 | 279 |
if (cli_writen(n->ofd, obuf, size) != (ssize_t) size) { |
279 | 280 |
cli_dbgmsg("NSIS: cannot write output file"__AT__"\n"); |
280 | 281 |
free(ibuf); |
281 | 282 |
close(n->ofd); |
283 |
+ nsis_shutdown(n); |
|
282 | 284 |
return CL_EIO; |
283 | 285 |
} |
284 | 286 |
n->nsis.next_out = obuf; |
... | ... |
@@ -290,27 +291,37 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { |
290 | 290 |
nsis_shutdown(n); |
291 | 291 |
return ret; |
292 | 292 |
} |
293 |
- } else if (++loops > 10) { |
|
293 |
+ } else if (++loops > 20) { |
|
294 | 294 |
cli_dbgmsg("NSIS: xs looping, breaking out"__AT__"\n"); |
295 |
- ret = CL_BREAK; |
|
295 |
+ ret = CL_EFORMAT; |
|
296 | 296 |
break; |
297 | 297 |
} |
298 | 298 |
} |
299 | 299 |
|
300 |
- if (ret != CL_BREAK) { |
|
301 |
- cli_dbgmsg("NSIS: bad stream"__AT__"\n"); |
|
302 |
- free(ibuf); |
|
303 |
- close(n->ofd); |
|
304 |
- return CL_EFORMAT; |
|
300 |
+ nsis_shutdown(n); |
|
301 |
+ |
|
302 |
+ if (n->nsis.next_out - obuf) { |
|
303 |
+ gotsome=1; |
|
304 |
+ if (cli_writen(n->ofd, obuf, n->nsis.next_out - obuf) != n->nsis.next_out - obuf) { |
|
305 |
+ cli_dbgmsg("NSIS: cannot write output file"__AT__"\n"); |
|
306 |
+ free(ibuf); |
|
307 |
+ close(n->ofd); |
|
308 |
+ return CL_EIO; |
|
309 |
+ } |
|
305 | 310 |
} |
306 | 311 |
|
307 |
- if (cli_writen(n->ofd, obuf, n->nsis.next_out - obuf) != n->nsis.next_out - obuf) { |
|
308 |
- cli_dbgmsg("NSIS: cannot write output file"__AT__"\n"); |
|
312 |
+ if (ret != CL_SUCCESS && ret != CL_BREAK) { |
|
313 |
+ cli_dbgmsg("NSIS: bad stream"__AT__"\n"); |
|
314 |
+ if (gotsome) { |
|
315 |
+ ret = CL_SUCCESS; |
|
316 |
+ } else { |
|
317 |
+ ret CL_EMAXSIZE; |
|
318 |
+ close(n->ofd); |
|
319 |
+ } |
|
309 | 320 |
free(ibuf); |
310 |
- close(n->ofd); |
|
311 |
- return CL_EIO; |
|
321 |
+ return ret; |
|
312 | 322 |
} |
313 |
- nsis_shutdown(n); |
|
323 |
+ |
|
314 | 324 |
} |
315 | 325 |
|
316 | 326 |
free(ibuf); |
... | ... |
@@ -388,32 +399,48 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { |
388 | 388 |
while (size && (ret=nsis_decomp(n))==CL_SUCCESS) { |
389 | 389 |
unsigned int wsz; |
390 | 390 |
if ((wsz = n->nsis.next_out - obuf)) { |
391 |
+ gotsome=1; |
|
391 | 392 |
if (cli_writen(n->ofd, obuf, wsz) != (ssize_t) wsz) { |
393 |
+ cli_dbgmsg("NSIS: cannot write output file"__AT__"\n"); |
|
392 | 394 |
close(n->ofd); |
393 | 395 |
return CL_EIO; |
394 | 396 |
} |
395 | 397 |
size-=wsz; |
398 |
+ loops=0; |
|
396 | 399 |
n->nsis.next_out = obuf; |
397 | 400 |
n->nsis.avail_out = MIN(size,BUFSIZ); |
398 | 401 |
} else if ( ++loops > 20 ) { |
399 | 402 |
cli_dbgmsg("NSIS: xs looping, breaking out"__AT__"\n"); |
400 |
- ret = CL_BREAK; |
|
403 |
+ ret = CL_EFORMAT; |
|
401 | 404 |
break; |
402 | 405 |
} |
403 | 406 |
} |
404 | 407 |
|
405 |
- if (ret == CL_BREAK) { |
|
408 |
+ if (n->nsis.next_out - obuf) { |
|
409 |
+ gotsome=1; |
|
406 | 410 |
if (cli_writen(n->ofd, obuf, n->nsis.next_out - obuf) != n->nsis.next_out - obuf) { |
411 |
+ cli_dbgmsg("NSIS: cannot write output file"__AT__"\n"); |
|
412 |
+ free(ibuf); |
|
407 | 413 |
close(n->ofd); |
408 | 414 |
return CL_EIO; |
409 | 415 |
} |
416 |
+ } |
|
417 |
+ |
|
418 |
+ if (ret == CL_EFORMAT) { |
|
419 |
+ cli_dbgmsg("NSIS: bad stream"__AT__"\n"); |
|
420 |
+ if (!gotsome) { |
|
421 |
+ close(n->ofd); |
|
422 |
+ return CL_EMAXSIZE; |
|
423 |
+ } |
|
424 |
+ } |
|
425 |
+ |
|
426 |
+ if (ret == CL_EFORMAT || ret == CL_BREAK) { |
|
410 | 427 |
n->eof=1; |
411 | 428 |
} else if (ret != CL_SUCCESS) { |
412 | 429 |
cli_dbgmsg("NSIS: bad stream"__AT__"\n"); |
413 | 430 |
close(n->ofd); |
414 | 431 |
return CL_EFORMAT; |
415 | 432 |
} |
416 |
- |
|
417 | 433 |
return CL_SUCCESS; |
418 | 434 |
} |
419 | 435 |
|
... | ... |
@@ -545,7 +572,6 @@ int cli_scannulsft(int desc, cli_ctx *ctx, off_t offset) { |
545 | 545 |
if(!cli_leavetemps_flag) |
546 | 546 |
unlink(nsist.ofn); |
547 | 547 |
} else if(ret == CL_EMAXSIZE) { |
548 |
- cli_errmsg("returned %d\n", ret); |
|
549 | 548 |
ret = nsist.solid ? CL_BREAK : CL_SUCCESS; |
550 | 549 |
} |
551 | 550 |
} while(ret == CL_SUCCESS); |