git-svn: trunk@2359
Tomasz Kojm authored on 2006/10/10 00:23:50... | ... |
@@ -27,7 +27,9 @@ |
27 | 27 |
#include <sys/types.h> |
28 | 28 |
#include <sys/stat.h> |
29 | 29 |
#include <fcntl.h> |
30 |
+#ifdef HAVE_UNISTD_H |
|
30 | 31 |
#include <unistd.h> |
32 |
+#endif |
|
31 | 33 |
#include <string.h> |
32 | 34 |
|
33 | 35 |
#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) |
... | ... |
@@ -55,6 +57,10 @@ |
55 | 55 |
#pragma pack(1) |
56 | 56 |
#endif |
57 | 57 |
|
58 |
+#ifndef O_BINARY |
|
59 |
+#define O_BINARY 0 |
|
60 |
+#endif |
|
61 |
+ |
|
58 | 62 |
#define CHM_ITSF_MIN_LEN (0x60) |
59 | 63 |
typedef struct itsf_header_tag |
60 | 64 |
{ |
... | ... |
@@ -831,7 +837,7 @@ static int chm_decompress_stream(int fd, const char *dirname, itsf_header_t *its |
831 | 831 |
mf_in.name = strdup("input"); |
832 | 832 |
|
833 | 833 |
snprintf(filename, 1024, "%s/clamav-unchm.bin", dirname); |
834 |
- mf_out.desc = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU); |
|
834 |
+ mf_out.desc = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU); |
|
835 | 835 |
if (!mf_out.desc) { |
836 | 836 |
cli_dbgmsg("open failed\n", filename); |
837 | 837 |
free(mf_in.name); |
... | ... |
@@ -920,7 +926,7 @@ static int chm_decompress_stream(int fd, const char *dirname, itsf_header_t *its |
920 | 920 |
mf_out.fh = NULL; |
921 | 921 |
|
922 | 922 |
/* Reopen the file for reading */ |
923 |
- mf_out.desc = open(filename, O_RDONLY); |
|
923 |
+ mf_out.desc = open(filename, O_RDONLY|O_BINARY); |
|
924 | 924 |
if (mf_out.desc < 0) { |
925 | 925 |
cli_dbgmsg("re-open output failed\n"); |
926 | 926 |
goto abort; |
... | ... |
@@ -942,7 +948,7 @@ static int chm_decompress_stream(int fd, const char *dirname, itsf_header_t *its |
942 | 942 |
} |
943 | 943 |
|
944 | 944 |
snprintf(filename, 1024, "%s/%d-%llu.chm", dirname, count, entry->offset); |
945 |
- ofd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU); |
|
945 |
+ ofd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU); |
|
946 | 946 |
if (ofd < 0) { |
947 | 947 |
entry = entry->next; |
948 | 948 |
continue; |
... | ... |
@@ -29,9 +29,12 @@ |
29 | 29 |
#include <sys/types.h> |
30 | 30 |
#include <sys/stat.h> |
31 | 31 |
#include <fcntl.h> |
32 |
+#ifdef HAVE_UNISTD_H |
|
32 | 33 |
#include <unistd.h> |
33 |
-#include <zlib.h> |
|
34 |
+#endif |
|
35 |
+#include "zlib.h" |
|
34 | 36 |
#include <time.h> |
37 |
+#include <errno.h> |
|
35 | 38 |
|
36 | 39 |
#include "clamav.h" |
37 | 40 |
#include "others.h" |
... | ... |
@@ -53,7 +56,7 @@ int cli_untgz(int fd, const char *destdir) |
53 | 53 |
cli_dbgmsg("in cli_untgz()\n"); |
54 | 54 |
|
55 | 55 |
if((infile = gzdopen(fd, "rb")) == NULL) { |
56 |
- cli_errmsg("Can't gzdopen() descriptor %d\n", fd); |
|
56 |
+ cli_errmsg("Can't gzdopen() descriptor %d, errno = %d\n", fd, errno); |
|
57 | 57 |
return -1; |
58 | 58 |
} |
59 | 59 |
|
... | ... |
@@ -403,10 +406,12 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short |
403 | 403 |
} |
404 | 404 |
|
405 | 405 |
if(cli_untgz(fd, dir)) { |
406 |
+ close(fd); |
|
406 | 407 |
cli_errmsg("cli_cvdload(): Can't unpack CVD file.\n"); |
407 | 408 |
free(dir); |
408 | 409 |
return CL_ECVDEXTR; |
409 | 410 |
} |
411 |
+ close(fd); |
|
410 | 412 |
|
411 | 413 |
/* load extracted directory */ |
412 | 414 |
ret = cl_load(dir, engine, signo, options); |
... | ... |
@@ -203,7 +203,7 @@ static char internat[256] = { |
203 | 203 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 /* 0xfX */ |
204 | 204 |
}; |
205 | 205 |
|
206 |
-cli_file_t cli_filetype(const char *buf, size_t buflen) |
|
206 |
+cli_file_t cli_filetype(const unsigned char *buf, size_t buflen) |
|
207 | 207 |
{ |
208 | 208 |
int i, ascii = 1, len; |
209 | 209 |
|
... | ... |
@@ -70,7 +70,7 @@ struct cli_matched_type { |
70 | 70 |
struct cli_matched_type *next; |
71 | 71 |
}; |
72 | 72 |
|
73 |
-cli_file_t cli_filetype(const char *buf, size_t buflen); |
|
73 |
+cli_file_t cli_filetype(const unsigned char *buf, size_t buflen); |
|
74 | 74 |
cli_file_t cli_filetype2(int desc); |
75 | 75 |
int cli_addtypesigs(struct cl_engine *engine); |
76 | 76 |
|
... | ... |
@@ -22,8 +22,14 @@ |
22 | 22 |
* MA 02110-1301, USA. |
23 | 23 |
*/ |
24 | 24 |
|
25 |
+#if HAVE_CONFIG_H |
|
26 |
+#include "clamav-config.h" |
|
27 |
+#endif |
|
28 |
+ |
|
25 | 29 |
#include <stdio.h> |
30 |
+#ifdef HAVE_UNISTD_H |
|
26 | 31 |
#include <unistd.h> |
32 |
+#endif |
|
27 | 33 |
#include <sys/types.h> |
28 | 34 |
#include <sys/stat.h> |
29 | 35 |
#include <fcntl.h> |
... | ... |
@@ -32,10 +38,6 @@ |
32 | 32 |
#include <stdio.h> |
33 | 33 |
#include <ctype.h> |
34 | 34 |
|
35 |
-#if HAVE_CONFIG_H |
|
36 |
-#include "clamav-config.h" |
|
37 |
-#endif |
|
38 |
- |
|
39 | 35 |
#if HAVE_MMAP |
40 | 36 |
#if HAVE_SYS_MMAN_H |
41 | 37 |
#include <sys/mman.h> |
... | ... |
@@ -29,7 +29,9 @@ |
29 | 29 |
#include <stdio.h> |
30 | 30 |
#include <string.h> |
31 | 31 |
#include <stdlib.h> |
32 |
+#ifdef HAVE_UNISTD_H |
|
32 | 33 |
#include <unistd.h> |
34 |
+#endif |
|
33 | 35 |
|
34 | 36 |
#include "clamav.h" |
35 | 37 |
#include "others.h" |
... | ... |
@@ -292,7 +294,7 @@ inline static int cli_findpos(const char *buffer, unsigned int depth, unsigned i |
292 | 292 |
return 1; |
293 | 293 |
} |
294 | 294 |
|
295 |
-int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cli_matcher *root, int *partcnt, unsigned short otfrec, unsigned long int offset, unsigned long int *partoff, unsigned short ftype, int fd, struct cli_matched_type **ftoffset) |
|
295 |
+int cli_ac_scanbuff(const unsigned char *buffer, unsigned int length, const char **virname, const struct cli_matcher *root, int *partcnt, unsigned short otfrec, unsigned long int offset, unsigned long int *partoff, unsigned short ftype, int fd, struct cli_matched_type **ftoffset) |
|
296 | 296 |
{ |
297 | 297 |
struct cli_ac_node *current; |
298 | 298 |
struct cli_ac_patt *pt; |
... | ... |
@@ -27,7 +27,7 @@ |
27 | 27 |
#define AC_DEFAULT_DEPTH 2 |
28 | 28 |
|
29 | 29 |
int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern); |
30 |
-int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cli_matcher *root, int *partcnt, unsigned short otfrec, unsigned long int offset, unsigned long int *partoff, unsigned short ftype, int fd, struct cli_matched_type **ftoffset); |
|
30 |
+int cli_ac_scanbuff(const unsigned char *buffer, unsigned int length, const char **virname, const struct cli_matcher *root, int *partcnt, unsigned short otfrec, unsigned long int offset, unsigned long int *partoff, unsigned short ftype, int fd, struct cli_matched_type **ftoffset); |
|
31 | 31 |
int cli_ac_buildtrie(struct cli_matcher *root); |
32 | 32 |
void cli_ac_free(struct cli_matcher *root); |
33 | 33 |
void cli_ac_setdepth(unsigned int depth); |
... | ... |
@@ -25,7 +25,9 @@ |
25 | 25 |
#include <ctype.h> |
26 | 26 |
#include <sys/types.h> |
27 | 27 |
#include <sys/stat.h> |
28 |
+#ifdef HAVE_UNISTD_H |
|
28 | 29 |
#include <unistd.h> |
30 |
+#endif |
|
29 | 31 |
|
30 | 32 |
#include "clamav.h" |
31 | 33 |
#include "others.h" |
... | ... |
@@ -396,7 +398,7 @@ int cli_validatesig(unsigned short ftype, const char *offstr, unsigned long int |
396 | 396 |
} |
397 | 397 |
|
398 | 398 |
if(fileoff != (unsigned long int) off) { |
399 |
- cli_dbgmsg("Virus offset: %d, expected: %d (%s)\n", fileoff, off, virname); |
|
399 |
+ cli_dbgmsg("Virus offset: %ld, expected: %ld (%s)\n", fileoff, off, virname); |
|
400 | 400 |
return 0; |
401 | 401 |
} |
402 | 402 |
} |
... | ... |
@@ -40,6 +40,7 @@ extern int mspack_sys_filelen(struct mspack_system *system, |
40 | 40 |
extern int mspack_valid_system(struct mspack_system *sys); |
41 | 41 |
|
42 | 42 |
/* inline memcmp() */ |
43 |
+#ifndef C_WINDOWS |
|
43 | 44 |
static inline int memcmp(const void *s1, const void *s2, size_t n) { |
44 | 45 |
unsigned char *c1 = (unsigned char *) s1; |
45 | 46 |
unsigned char *c2 = (unsigned char *) s2; |
... | ... |
@@ -54,5 +55,6 @@ static inline size_t strlen(const char *s) { |
54 | 54 |
while (*e) e++; |
55 | 55 |
return e - s; |
56 | 56 |
} |
57 |
+#endif |
|
57 | 58 |
|
58 | 59 |
#endif |
... | ... |
@@ -30,10 +30,12 @@ |
30 | 30 |
#include <fcntl.h> |
31 | 31 |
#include <stdio.h> |
32 | 32 |
#include <string.h> |
33 |
+#ifdef HAVE_UNISTD_H |
|
33 | 34 |
#include <unistd.h> |
35 |
+#endif |
|
34 | 36 |
#include <ctype.h> |
35 | 37 |
#include <stdlib.h> |
36 |
-#include <clamav.h> |
|
38 |
+#include "clamav.h" |
|
37 | 39 |
|
38 | 40 |
#if HAVE_MMAP |
39 | 41 |
#if HAVE_SYS_MMAN_H |
... | ... |
@@ -58,6 +60,10 @@ |
58 | 58 |
#pragma pack(1) |
59 | 59 |
#endif |
60 | 60 |
|
61 |
+#ifndef O_BINARY |
|
62 |
+#define O_BINARY 0 |
|
63 |
+#endif |
|
64 |
+ |
|
61 | 65 |
typedef struct ole2_header_tag |
62 | 66 |
{ |
63 | 67 |
unsigned char magic[8] __attribute__ ((packed)); /* should be: 0xd0cf11e0a1b11ae1 */ |
... | ... |
@@ -135,7 +141,7 @@ static char *get_property_name(char *name, int size) |
135 | 135 |
j=0; |
136 | 136 |
/* size-2 to ignore trailing NULL */ |
137 | 137 |
for (i=0 ; i < size-2; i+=2) { |
138 |
- if (isprint(name[i])) { |
|
138 |
+ if((!(name[i]&0x80)) && isprint(name[i])) { |
|
139 | 139 |
newname[j++] = name[i]; |
140 | 140 |
} else { |
141 | 141 |
if (name[i] < 10 && name[i] >= 0) { |
... | ... |
@@ -587,8 +593,8 @@ static int handler_writefile(int fd, ole2_header_t *hdr, property_t *prop, const |
587 | 587 |
#ifdef C_DARWIN |
588 | 588 |
*newname &= '\177'; |
589 | 589 |
#endif |
590 |
-#if defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32) || defined(C_OS2) |
|
591 |
- if(strchr("/*?<>|\"+=,;: ", *newname)) |
|
590 |
+#if defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32) || defined(C_OS2) || defined(C_WINDOWS) |
|
591 |
+ if(strchr("/*?<>|\"+=,;:\\ ", *newname)) |
|
592 | 592 |
#else |
593 | 593 |
if(*newname == '/') |
594 | 594 |
#endif |
... | ... |
@@ -602,10 +608,11 @@ static int handler_writefile(int fd, ole2_header_t *hdr, property_t *prop, const |
602 | 602 |
free(name); |
603 | 603 |
return FALSE; |
604 | 604 |
} |
605 |
+ |
|
605 | 606 |
sprintf(newname, "%s/%s", dir, name); |
606 | 607 |
free(name); |
607 | 608 |
|
608 |
- ofd = open(newname, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU); |
|
609 |
+ ofd = open(newname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU); |
|
609 | 610 |
if (ofd < 0) { |
610 | 611 |
cli_errmsg("ERROR: failed to create file: %s\n", newname); |
611 | 612 |
free(newname); |
... | ... |
@@ -100,8 +100,13 @@ typedef struct { |
100 | 100 |
#define ROL(a,b) a = ( a << (b % (sizeof(a)<<3) )) | (a >> ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) ) |
101 | 101 |
#define ROR(a,b) a = ( a >> (b % (sizeof(a)<<3) )) | (a << ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) ) |
102 | 102 |
|
103 |
+#ifndef FALSE |
|
103 | 104 |
#define FALSE (0) |
105 |
+#endif |
|
106 |
+ |
|
107 |
+#ifndef TRUE |
|
104 | 108 |
#define TRUE (1) |
109 |
+#endif |
|
105 | 110 |
|
106 | 111 |
#ifndef MIN |
107 | 112 |
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
... | ... |
@@ -25,16 +25,24 @@ |
25 | 25 |
#include <stdlib.h> |
26 | 26 |
#include <string.h> |
27 | 27 |
#include <ctype.h> |
28 |
+#ifdef HAVE_UNISTD_H |
|
28 | 29 |
#include <unistd.h> |
30 |
+#endif |
|
31 |
+#ifndef C_WINDOWS |
|
29 | 32 |
#include <dirent.h> |
33 |
+#endif |
|
30 | 34 |
#include <sys/types.h> |
31 | 35 |
#include <sys/stat.h> |
36 |
+#ifdef HAVE_SYS_PARAM_H |
|
32 | 37 |
#include <sys/param.h> |
38 |
+#endif |
|
33 | 39 |
#include <fcntl.h> |
34 | 40 |
|
35 | 41 |
#include "clamav.h" |
36 | 42 |
#include "cvd.h" |
37 |
-#include "strings.h" |
|
43 |
+#ifdef HAVE_STRINGS_H |
|
44 |
+#include <strings.h> |
|
45 |
+#endif |
|
38 | 46 |
#include "matcher-ac.h" |
39 | 47 |
#include "matcher-bm.h" |
40 | 48 |
#include "others.h" |
... | ... |
@@ -1221,7 +1229,7 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine **engine, unsigne |
1221 | 1221 |
#else |
1222 | 1222 |
while((dent = readdir(dd))) { |
1223 | 1223 |
#endif |
1224 |
-#ifndef C_INTERIX |
|
1224 |
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(C_CYGWIN)) |
|
1225 | 1225 |
if(dent->d_ino) |
1226 | 1226 |
#endif |
1227 | 1227 |
{ |
... | ... |
@@ -1342,7 +1350,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat) |
1342 | 1342 |
#else |
1343 | 1343 |
while((dent = readdir(dd))) { |
1344 | 1344 |
#endif |
1345 |
-#ifndef C_INTERIX |
|
1345 |
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(C_CYGWIN)) |
|
1346 | 1346 |
if(dent->d_ino) |
1347 | 1347 |
#endif |
1348 | 1348 |
{ |
... | ... |
@@ -1421,7 +1429,7 @@ int cl_statchkdir(const struct cl_stat *dbstat) |
1421 | 1421 |
#else |
1422 | 1422 |
while((dent = readdir(dd))) { |
1423 | 1423 |
#endif |
1424 |
-#ifndef C_INTERIX |
|
1424 |
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(C_CYGWIN)) |
|
1425 | 1425 |
if(dent->d_ino) |
1426 | 1426 |
#endif |
1427 | 1427 |
{ |
... | ... |
@@ -26,12 +26,17 @@ |
26 | 26 |
#include <stdlib.h> |
27 | 27 |
#include <sys/types.h> |
28 | 28 |
#include <sys/stat.h> |
29 |
+#ifdef HAVE_UNISTD_H |
|
29 | 30 |
#include <unistd.h> |
31 |
+#endif |
|
32 |
+#ifdef HAVE_SYS_PARAM_H |
|
30 | 33 |
#include <sys/param.h> |
34 |
+#endif |
|
31 | 35 |
#include <fcntl.h> |
36 |
+#ifndef C_WINDOWS |
|
32 | 37 |
#include <dirent.h> |
33 | 38 |
#include <netinet/in.h> |
34 |
- |
|
39 |
+#endif |
|
35 | 40 |
|
36 | 41 |
#if HAVE_MMAP |
37 | 42 |
#if HAVE_SYS_MMAN_H |
... | ... |
@@ -43,6 +48,10 @@ |
43 | 43 |
|
44 | 44 |
#include <mspack.h> |
45 | 45 |
|
46 |
+#ifndef O_BINARY |
|
47 |
+#define O_BINARY 0 |
|
48 |
+#endif |
|
49 |
+ |
|
46 | 50 |
extern short cli_leavetemps_flag; |
47 | 51 |
|
48 | 52 |
#include "clamav.h" |
... | ... |
@@ -868,7 +877,7 @@ int cli_scandir(const char *dirname, cli_ctx *ctx) |
868 | 868 |
#else |
869 | 869 |
while((dent = readdir(dd))) { |
870 | 870 |
#endif |
871 |
-#ifndef C_INTERIX |
|
871 |
+#if (!defined(C_CYGWIN)) && (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) |
|
872 | 872 |
if(dent->d_ino) |
873 | 873 |
#endif |
874 | 874 |
{ |
... | ... |
@@ -930,7 +939,7 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx) |
930 | 930 |
for(i = 0; i < vba_project->count; i++) { |
931 | 931 |
fullname = (char *) cli_malloc(strlen(vba_project->dir) + strlen(vba_project->name[i]) + 2); |
932 | 932 |
sprintf(fullname, "%s/%s", vba_project->dir, vba_project->name[i]); |
933 |
- fd = open(fullname, O_RDONLY); |
|
933 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
934 | 934 |
if(fd == -1) { |
935 | 935 |
cli_dbgmsg("VBADir: Can't open file %s\n", fullname); |
936 | 936 |
free(fullname); |
... | ... |
@@ -975,7 +984,7 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx) |
975 | 975 |
for (i = 0; i < vba_project->count; i++) { |
976 | 976 |
fullname = (char *) cli_malloc(strlen(vba_project->dir) + strlen(vba_project->name[i]) + 2); |
977 | 977 |
sprintf(fullname, "%s/%s", vba_project->dir, vba_project->name[i]); |
978 |
- fd = open(fullname, O_RDONLY); |
|
978 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
979 | 979 |
if(fd == -1) { |
980 | 980 |
cli_dbgmsg("VBADir: Can't open file %s\n", fullname); |
981 | 981 |
free(fullname); |
... | ... |
@@ -1019,7 +1028,7 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx) |
1019 | 1019 |
/* Check directory for embedded OLE objects */ |
1020 | 1020 |
fullname = (char *) cli_malloc(strlen(dirname) + 16); |
1021 | 1021 |
sprintf(fullname, "%s/_1_Ole10Native", dirname); |
1022 |
- fd = open(fullname, O_RDONLY); |
|
1022 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
1023 | 1023 |
free(fullname); |
1024 | 1024 |
if (fd >= 0) { |
1025 | 1025 |
ofd = cli_decode_ole_object(fd, dirname); |
... | ... |
@@ -1040,7 +1049,7 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx) |
1040 | 1040 |
#else |
1041 | 1041 |
while((dent = readdir(dd))) { |
1042 | 1042 |
#endif |
1043 |
-#ifndef C_INTERIX |
|
1043 |
+#if (!defined(C_CYGWIN)) && (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) |
|
1044 | 1044 |
if(dent->d_ino) |
1045 | 1045 |
#endif |
1046 | 1046 |
{ |
... | ... |
@@ -1088,7 +1097,7 @@ static int cli_scanhtml(int desc, cli_ctx *ctx) |
1088 | 1088 |
|
1089 | 1089 |
html_normalise_fd(desc, tempname, NULL); |
1090 | 1090 |
snprintf(fullname, 1024, "%s/comment.html", tempname); |
1091 |
- fd = open(fullname, O_RDONLY); |
|
1091 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
1092 | 1092 |
if (fd >= 0) { |
1093 | 1093 |
ret = cli_scandesc(fd, ctx, 0, CL_TYPE_HTML, NULL); |
1094 | 1094 |
close(fd); |
... | ... |
@@ -1103,7 +1112,7 @@ static int cli_scanhtml(int desc, cli_ctx *ctx) |
1103 | 1103 |
|
1104 | 1104 |
if (ret == CL_CLEAN) { |
1105 | 1105 |
snprintf(fullname, 1024, "%s/nocomment.html", tempname); |
1106 |
- fd = open(fullname, O_RDONLY); |
|
1106 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
1107 | 1107 |
if (fd >= 0) { |
1108 | 1108 |
ret = cli_scandesc(fd, ctx, 0, CL_TYPE_HTML, NULL); |
1109 | 1109 |
close(fd); |
... | ... |
@@ -1119,7 +1128,7 @@ static int cli_scanhtml(int desc, cli_ctx *ctx) |
1119 | 1119 |
|
1120 | 1120 |
if (ret == CL_CLEAN) { |
1121 | 1121 |
snprintf(fullname, 1024, "%s/script.html", tempname); |
1122 |
- fd = open(fullname, O_RDONLY); |
|
1122 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
1123 | 1123 |
if (fd >= 0) { |
1124 | 1124 |
ret = cli_scandesc(fd, ctx, 0, CL_TYPE_HTML, NULL); |
1125 | 1125 |
close(fd); |
... | ... |
@@ -1357,7 +1366,7 @@ static int cli_scancryptff(int desc, cli_ctx *ctx) |
1357 | 1357 |
free(src); |
1358 | 1358 |
|
1359 | 1359 |
tempfile = cli_gentemp(NULL); |
1360 |
- if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) { |
|
1360 |
+ if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { |
|
1361 | 1361 |
cli_errmsg("CryptFF: Can't create file %s\n", tempfile); |
1362 | 1362 |
free(dest); |
1363 | 1363 |
free(tempfile); |
... | ... |
@@ -1848,7 +1857,7 @@ static int cli_scanfile(const char *filename, cli_ctx *ctx) |
1848 | 1848 |
int fd, ret; |
1849 | 1849 |
|
1850 | 1850 |
/* internal version of cl_scanfile with arec/mrec preserved */ |
1851 |
- if((fd = open(filename, O_RDONLY)) == -1) |
|
1851 |
+ if((fd = open(filename, O_RDONLY|O_BINARY)) == -1) |
|
1852 | 1852 |
return CL_EOPEN; |
1853 | 1853 |
|
1854 | 1854 |
ret = cli_magic_scandesc(fd, ctx); |
... | ... |
@@ -1862,7 +1871,7 @@ int cl_scanfile(const char *filename, const char **virname, unsigned long int *s |
1862 | 1862 |
int fd, ret; |
1863 | 1863 |
|
1864 | 1864 |
|
1865 |
- if((fd = open(filename, O_RDONLY)) == -1) |
|
1865 |
+ if((fd = open(filename, O_RDONLY|O_BINARY)) == -1) |
|
1866 | 1866 |
return CL_EOPEN; |
1867 | 1867 |
|
1868 | 1868 |
ret = cl_scandesc(fd, virname, scanned, engine, limits, options); |
... | ... |
@@ -17,13 +17,21 @@ |
17 | 17 |
* MA 02110-1301, USA. |
18 | 18 |
*/ |
19 | 19 |
|
20 |
+#ifdef _MSC_VER |
|
21 |
+#include <windows.h> |
|
22 |
+#endif |
|
23 |
+ |
|
20 | 24 |
#include "clamav-config.h" |
21 | 25 |
|
22 | 26 |
#include <sys/types.h> |
23 | 27 |
#include <sys/stat.h> |
24 | 28 |
#include <fcntl.h> |
29 |
+#ifdef HAVE_UNISTD_H |
|
25 | 30 |
#include <unistd.h> |
31 |
+#endif |
|
32 |
+#ifndef C_WINDOWS |
|
26 | 33 |
#include <netinet/in.h> |
34 |
+#endif |
|
27 | 35 |
#include <string.h> |
28 | 36 |
|
29 | 37 |
#include "clamav.h" |
... | ... |
@@ -25,7 +25,9 @@ |
25 | 25 |
#define UNRAR_H 1 |
26 | 26 |
|
27 | 27 |
#include <sys/types.h> |
28 |
+#ifdef HAVE_UNISTD_H |
|
28 | 29 |
#include <unistd.h> |
30 |
+#endif |
|
29 | 31 |
|
30 | 32 |
/* #define RAR_DEBUG */ |
31 | 33 |
/* #define RAR_HIGH_DEBUG */ |
... | ... |
@@ -108,6 +110,14 @@ typedef struct mark_header_tag |
108 | 108 |
unsigned char mark[SIZEOF_MARKHEAD]; |
109 | 109 |
} mark_header_t; |
110 | 110 |
|
111 |
+#ifndef HAVE_ATTRIB_PACKED |
|
112 |
+#define __attribute__(x) |
|
113 |
+#endif |
|
114 |
+ |
|
115 |
+#ifdef HAVE_PRAGMA_PACK |
|
116 |
+#pragma pack(1) |
|
117 |
+#endif |
|
118 |
+ |
|
111 | 119 |
typedef struct main_header_tag |
112 | 120 |
{ |
113 | 121 |
uint16_t head_crc __attribute__ ((packed)); |
... | ... |
@@ -20,8 +20,14 @@ |
20 | 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
21 | 21 |
* MA 02110-1301, USA. |
22 | 22 |
*/ |
23 |
+#if HAVE_CONFIG_H |
|
24 |
+#include "clamav-config.h" |
|
25 |
+#endif |
|
23 | 26 |
|
27 |
+ |
|
28 |
+#ifdef HAVE_UNISTD_H |
|
24 | 29 |
#include <unistd.h> |
30 |
+#endif |
|
25 | 31 |
|
26 | 32 |
#include "unrar.h" |
27 | 33 |
#include "unrarfilter.h" |
... | ... |
@@ -319,7 +319,7 @@ static unsigned int filter_itanium_getbits(unsigned char *data, int bit_pos, int |
319 | 319 |
{ |
320 | 320 |
int in_addr=bit_pos/8; |
321 | 321 |
int in_bit=bit_pos&7; |
322 |
- unsigned int bit_field=(uint)data[in_addr++]; |
|
322 |
+ unsigned int bit_field=(unsigned int)data[in_addr++]; |
|
323 | 323 |
bit_field|=(unsigned int)data[in_addr++] << 8; |
324 | 324 |
bit_field|=(unsigned int)data[in_addr++] << 16; |
325 | 325 |
bit_field|=(unsigned int)data[in_addr] << 24; |
... | ... |
@@ -23,7 +23,9 @@ |
23 | 23 |
|
24 | 24 |
#include <stdio.h> |
25 | 25 |
#include <string.h> |
26 |
+#ifdef HAVE_UNISTD_H |
|
26 | 27 |
#include <unistd.h> |
28 |
+#endif |
|
27 | 29 |
#include <sys/types.h> |
28 | 30 |
#include <sys/stat.h> |
29 | 31 |
#include <fcntl.h> |
... | ... |
@@ -40,6 +42,10 @@ |
40 | 40 |
#include "vba_extract.h" |
41 | 41 |
#include "others.h" |
42 | 42 |
|
43 |
+#ifndef O_BINARY |
|
44 |
+#define O_BINARY 0 |
|
45 |
+#endif |
|
46 |
+ |
|
43 | 47 |
typedef struct vba_version_tag { |
44 | 48 |
unsigned char signature[4]; |
45 | 49 |
const char *name; |
... | ... |
@@ -264,7 +270,7 @@ vba_project_t *vba56_dir_read(const char *dir) |
264 | 264 |
return NULL; |
265 | 265 |
} |
266 | 266 |
sprintf(fullname, "%s/_VBA_PROJECT", dir); |
267 |
- fd = open(fullname, O_RDONLY); |
|
267 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
268 | 268 |
|
269 | 269 |
if (fd == -1) { |
270 | 270 |
cli_dbgmsg("Can't open %s\n", fullname); |
... | ... |
@@ -744,7 +750,7 @@ int cli_decode_ole_object(int fd, const char *dir) |
744 | 744 |
} |
745 | 745 |
fullname = cli_malloc(strlen(dir) + 18); |
746 | 746 |
sprintf(fullname, "%s/_clam_ole_object", dir); |
747 |
- ofd = open(fullname, O_RDWR|O_CREAT|O_TRUNC, 0600); |
|
747 |
+ ofd = open(fullname, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600); |
|
748 | 748 |
free(fullname); |
749 | 749 |
if (ofd < 0) { |
750 | 750 |
return -1; |
... | ... |
@@ -814,7 +820,7 @@ static int ppt_unlzw(const char *dir, int fd, uint32_t length) |
814 | 814 |
} |
815 | 815 |
sprintf(fullname, "%s/ppt%.8lx.doc", dir, lseek(fd, 0, SEEK_CUR)); |
816 | 816 |
|
817 |
- ofd = open(fullname, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
|
817 |
+ ofd = open(fullname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600); |
|
818 | 818 |
free(fullname); |
819 | 819 |
if (ofd == -1) { |
820 | 820 |
cli_dbgmsg("ppt_unlzw Open outfile failed\n"); |
... | ... |
@@ -946,7 +952,7 @@ char *ppt_vba_read(const char *dir) |
946 | 946 |
return NULL; |
947 | 947 |
} |
948 | 948 |
sprintf(fullname, "%s/PowerPoint Document", dir); |
949 |
- fd = open(fullname, O_RDONLY); |
|
949 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
950 | 950 |
free(fullname); |
951 | 951 |
if (fd == -1) { |
952 | 952 |
cli_dbgmsg("Open PowerPoint Document failed\n"); |
... | ... |
@@ -1529,7 +1535,7 @@ vba_project_t *wm_dir_read(const char *dir) |
1529 | 1529 |
return NULL; |
1530 | 1530 |
} |
1531 | 1531 |
sprintf(fullname, "%s/WordDocument", dir); |
1532 |
- fd = open(fullname, O_RDONLY); |
|
1532 |
+ fd = open(fullname, O_RDONLY|O_BINARY); |
|
1533 | 1533 |
free(fullname); |
1534 | 1534 |
if (fd == -1) { |
1535 | 1535 |
cli_dbgmsg("Open WordDocument failed\n"); |