git-svn: trunk@2459
Tomasz Kojm authored on 2006/10/30 00:35:12... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Sun Oct 29 16:33:01 CET 2006 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * shared/cdiff.c: make cdiff_apply() compatible with old zlib versions |
|
4 |
+ (closes bug#76), patch from Ian Abbott <abbotti*mev.co.uk> |
|
5 |
+ |
|
1 | 6 |
Sun Oct 29 16:10:08 CET 2006 (tk) |
2 | 7 |
--------------------------------- |
3 | 8 |
* clamd/others.c: fix compilation error under w32 (closes bug#68) |
... | ... |
@@ -766,7 +766,8 @@ int cdiff_apply(int fd, unsigned short mode) |
766 | 766 |
gzFile *gzh; |
767 | 767 |
char line[1024], buff[FILEBUFF], *dsig = NULL; |
768 | 768 |
unsigned int lines = 0, cmds = 0; |
769 |
- int end, i; |
|
769 |
+ unsigned int difflen, diffremain; |
|
770 |
+ int end, i, n; |
|
770 | 771 |
struct stat sb; |
771 | 772 |
int desc; |
772 | 773 |
#ifdef HAVE_GMP |
... | ... |
@@ -859,12 +860,15 @@ int cdiff_apply(int fd, unsigned short mode) |
859 | 859 |
} |
860 | 860 |
|
861 | 861 |
i = 0; |
862 |
- while(read(desc, buff, 1) > 0) |
|
863 |
- if(buff[0] == ':') |
|
862 |
+ n = 0; |
|
863 |
+ while(n < FILEBUFF - 1 && read(desc, &buff[n], 1) > 0) { |
|
864 |
+ if(buff[n++] == ':') |
|
864 | 865 |
if(++i == 3) |
865 | 866 |
break; |
867 |
+ } |
|
868 |
+ buff[n] = 0; |
|
866 | 869 |
|
867 |
- if(i != 3) { |
|
870 |
+ if(sscanf(buff, "ClamAV-Diff:%*u:%u:", &difflen) != 1) { |
|
868 | 871 |
logg("!cdiff_apply: Incorrect file format\n"); |
869 | 872 |
close(desc); |
870 | 873 |
return -1; |
... | ... |
@@ -876,7 +880,17 @@ int cdiff_apply(int fd, unsigned short mode) |
876 | 876 |
return -1; |
877 | 877 |
} |
878 | 878 |
|
879 |
- while(gzgets(gzh, line, sizeof(line))) { |
|
879 |
+ diffremain = difflen; |
|
880 |
+ while(diffremain) { |
|
881 |
+ unsigned int bufsize = diffremain < sizeof(line) ? diffremain + 1 : sizeof(line); |
|
882 |
+ |
|
883 |
+ if(!gzgets(gzh, line, bufsize)) { |
|
884 |
+ logg("!cdiff_apply: Premature EOF at line %d\n", lines + 1); |
|
885 |
+ cdiff_ctx_free(&ctx); |
|
886 |
+ gzclose(gzh); |
|
887 |
+ return -1; |
|
888 |
+ } |
|
889 |
+ diffremain -= strlen(line); |
|
880 | 890 |
lines++; |
881 | 891 |
cli_chomp(line); |
882 | 892 |
|