git-svn: trunk@3683
Tomasz Kojm authored on 2008/02/28 01:39:50... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Wed Feb 27 16:42:27 CET 2008 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav/cab.c: fix handling of stored files |
|
4 |
+ |
|
1 | 5 |
Wed Feb 27 16:59:54 EET 2008 (edwin) |
2 | 6 |
------------------------------------ |
3 | 7 |
* libclamav/htmlnorm.c: don't add newline between script tags. |
... | ... |
@@ -567,7 +567,7 @@ static int cab_read(struct cab_file *file, unsigned char *buffer, int bytes) |
567 | 567 |
|
568 | 568 |
static int cab_unstore(struct cab_file *file, int bytes) |
569 | 569 |
{ |
570 |
- int todo; |
|
570 |
+ int todo, bread; |
|
571 | 571 |
unsigned char buff[4096]; |
572 | 572 |
|
573 | 573 |
|
... | ... |
@@ -580,26 +580,23 @@ static int cab_unstore(struct cab_file *file, int bytes) |
580 | 580 |
|
581 | 581 |
while(1) { |
582 | 582 |
|
583 |
- if((unsigned int) todo <= sizeof(buff)) { |
|
584 |
- if(cab_read(file, buff, todo) == -1) { |
|
585 |
- cli_dbgmsg("cab_unstore: cab_read failed for descriptor %d\n", file->fd); |
|
586 |
- return CL_EIO; |
|
587 |
- } else if(cli_writen(file->ofd, buff, todo) == -1) { |
|
588 |
- cli_dbgmsg("cab_unstore: Can't write to descriptor %d\n", file->ofd); |
|
589 |
- return CL_EIO; |
|
590 |
- } |
|
591 |
- break; |
|
583 |
+ if((unsigned int) todo <= sizeof(buff)) |
|
584 |
+ bread = todo; |
|
585 |
+ else |
|
586 |
+ bread = sizeof(buff); |
|
592 | 587 |
|
593 |
- } else { |
|
594 |
- if(cab_read(file, buff, sizeof(buff)) == -1) { |
|
595 |
- cli_dbgmsg("cab_unstore: cab_read failed for descriptor %d\n", file->fd); |
|
596 |
- return CL_EIO; |
|
597 |
- } else if(cli_writen(file->ofd, buff, sizeof(buff)) == -1) { |
|
598 |
- cli_dbgmsg("cab_unstore: Can't write to descriptor %d\n", file->ofd); |
|
599 |
- return CL_EIO; |
|
600 |
- } |
|
601 |
- todo -= sizeof(buff); |
|
588 |
+ if((bread = cab_read(file, buff, bread)) == -1) { |
|
589 |
+ cli_dbgmsg("cab_unstore: cab_read failed for descriptor %d\n", file->fd); |
|
590 |
+ return file->error; |
|
591 |
+ } else if(cli_writen(file->ofd, buff, bread) != bread) { |
|
592 |
+ cli_warnmsg("cab_unstore: Can't write %d bytes to descriptor %d\n", bread, file->ofd); |
|
593 |
+ return CL_EIO; |
|
602 | 594 |
} |
595 |
+ |
|
596 |
+ todo -= bread; |
|
597 |
+ |
|
598 |
+ if(!bread || todo <= 0) |
|
599 |
+ break; |
|
603 | 600 |
} |
604 | 601 |
|
605 | 602 |
return CL_SUCCESS; |