... | ... |
@@ -72,6 +72,8 @@ endif |
72 | 72 |
|
73 | 73 |
libclamav_internal_utils_la_SOURCES=str.c\ |
74 | 74 |
str.h\ |
75 |
+ iowrap.c \ |
|
76 |
+ iowrap.h \ |
|
75 | 77 |
md5.c\ |
76 | 78 |
md5.h\ |
77 | 79 |
others_common.c \ |
... | ... |
@@ -93,6 +95,8 @@ libclamav_internal_utils_la_CFLAGS=$(AM_CFLAGS) -fPIC -DPIC |
93 | 93 |
|
94 | 94 |
libclamav_internal_utils_nothreads_la_SOURCES=str.c\ |
95 | 95 |
str.h\ |
96 |
+ iowrap.c \ |
|
97 |
+ iowrap.h \ |
|
96 | 98 |
md5.c\ |
97 | 99 |
md5.h\ |
98 | 100 |
others_common.c \ |
... | ... |
@@ -231,6 +231,7 @@ libclamav_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ |
231 | 231 |
libclamav_internal_utils_la_LIBADD = |
232 | 232 |
am_libclamav_internal_utils_la_OBJECTS = \ |
233 | 233 |
libclamav_internal_utils_la-str.lo \ |
234 |
+ libclamav_internal_utils_la-iowrap.lo \ |
|
234 | 235 |
libclamav_internal_utils_la-md5.lo \ |
235 | 236 |
libclamav_internal_utils_la-others_common.lo \ |
236 | 237 |
libclamav_internal_utils_la-qsort.lo \ |
... | ... |
@@ -248,6 +249,7 @@ libclamav_internal_utils_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ |
248 | 248 |
libclamav_internal_utils_nothreads_la_LIBADD = |
249 | 249 |
am_libclamav_internal_utils_nothreads_la_OBJECTS = \ |
250 | 250 |
libclamav_internal_utils_nothreads_la-str.lo \ |
251 |
+ libclamav_internal_utils_nothreads_la-iowrap.lo \ |
|
251 | 252 |
libclamav_internal_utils_nothreads_la-md5.lo \ |
252 | 253 |
libclamav_internal_utils_nothreads_la-others_common.lo \ |
253 | 254 |
libclamav_internal_utils_nothreads_la-qsort.lo \ |
... | ... |
@@ -585,6 +587,8 @@ EXTRA_DIST = c++/Makefile.nollvm.in $(am__append_4) regex/engine.c \ |
585 | 585 |
@ENABLE_UNRAR_TRUE@IFACEDEP = libclamunrar_iface.la |
586 | 586 |
libclamav_internal_utils_la_SOURCES = str.c\ |
587 | 587 |
str.h\ |
588 |
+ iowrap.c\ |
|
589 |
+ iowrap.h\ |
|
588 | 590 |
md5.c\ |
589 | 591 |
md5.h\ |
590 | 592 |
others_common.c \ |
... | ... |
@@ -605,6 +609,8 @@ libclamav_internal_utils_la_LDFLAGS = -static |
605 | 605 |
libclamav_internal_utils_la_CFLAGS = $(AM_CFLAGS) -fPIC -DPIC |
606 | 606 |
libclamav_internal_utils_nothreads_la_SOURCES = str.c\ |
607 | 607 |
str.h\ |
608 |
+ iowrap.c\ |
|
609 |
+ iowrap.h\ |
|
608 | 610 |
md5.c\ |
609 | 611 |
md5.h\ |
610 | 612 |
others_common.c \ |
... | ... |
@@ -845,6 +851,7 @@ distclean-compile: |
845 | 845 |
-rm -f *.tab.c |
846 | 846 |
|
847 | 847 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bytecode_nojit.Plo@am__quote@ |
848 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-iowrap.Plo@am__quote@ |
|
848 | 849 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-md5.Plo@am__quote@ |
849 | 850 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-others_common.Plo@am__quote@ |
850 | 851 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-qsort.Plo@am__quote@ |
... | ... |
@@ -854,6 +861,7 @@ distclean-compile: |
854 | 854 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-regfree.Plo@am__quote@ |
855 | 855 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-str.Plo@am__quote@ |
856 | 856 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-strlcpy.Plo@am__quote@ |
857 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_nothreads_la-iowrap.Plo@am__quote@ |
|
857 | 858 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_nothreads_la-md5.Plo@am__quote@ |
858 | 859 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_nothreads_la-others_common.Plo@am__quote@ |
859 | 860 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_nothreads_la-qsort.Plo@am__quote@ |
... | ... |
@@ -2437,6 +2445,13 @@ libclamav_internal_utils_la-str.lo: str.c |
2437 | 2437 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
2438 | 2438 |
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -c -o libclamav_internal_utils_la-str.lo `test -f 'str.c' || echo '$(srcdir)/'`str.c |
2439 | 2439 |
|
2440 |
+libclamav_internal_utils_la-iowrap.lo: iowrap.c |
|
2441 |
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -MT libclamav_internal_utils_la-iowrap.lo -MD -MP -MF $(DEPDIR)/libclamav_internal_utils_la-iowrap.Tpo -c -o libclamav_internal_utils_la-iowrap.lo `test -f 'iowrap.c' || echo '$(srcdir)/'`iowrap.c |
|
2442 |
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libclamav_internal_utils_la-iowrap.Tpo $(DEPDIR)/libclamav_internal_utils_la-iowrap.Plo |
|
2443 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='iowrap.c' object='libclamav_internal_utils_la-iowrap.lo' libtool=yes @AMDEPBACKSLASH@ |
|
2444 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
2445 |
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -c -o libclamav_internal_utils_la-iowrap.lo `test -f 'iowrap.c' || echo '$(srcdir)/'`iowrap.c |
|
2446 |
+ |
|
2440 | 2447 |
libclamav_internal_utils_la-md5.lo: md5.c |
2441 | 2448 |
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -MT libclamav_internal_utils_la-md5.lo -MD -MP -MF $(DEPDIR)/libclamav_internal_utils_la-md5.Tpo -c -o libclamav_internal_utils_la-md5.lo `test -f 'md5.c' || echo '$(srcdir)/'`md5.c |
2442 | 2449 |
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libclamav_internal_utils_la-md5.Tpo $(DEPDIR)/libclamav_internal_utils_la-md5.Plo |
... | ... |
@@ -2500,6 +2515,13 @@ libclamav_internal_utils_nothreads_la-str.lo: str.c |
2500 | 2500 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
2501 | 2501 |
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_nothreads_la_CFLAGS) $(CFLAGS) -c -o libclamav_internal_utils_nothreads_la-str.lo `test -f 'str.c' || echo '$(srcdir)/'`str.c |
2502 | 2502 |
|
2503 |
+libclamav_internal_utils_nothreads_la-iowrap.lo: iowrap.c |
|
2504 |
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_nothreads_la_CFLAGS) $(CFLAGS) -MT libclamav_internal_utils_nothreads_la-iowrap.lo -MD -MP -MF $(DEPDIR)/libclamav_internal_utils_nothreads_la-iowrap.Tpo -c -o libclamav_internal_utils_nothreads_la-iowrap.lo `test -f 'iowrap.c' || echo '$(srcdir)/'`iowrap.c |
|
2505 |
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libclamav_internal_utils_nothreads_la-iowrap.Tpo $(DEPDIR)/libclamav_internal_utils_nothreads_la-iowrap.Plo |
|
2506 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='iowrap.c' object='libclamav_internal_utils_nothreads_la-iowrap.lo' libtool=yes @AMDEPBACKSLASH@ |
|
2507 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
2508 |
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_nothreads_la_CFLAGS) $(CFLAGS) -c -o libclamav_internal_utils_nothreads_la-iowrap.lo `test -f 'iowrap.c' || echo '$(srcdir)/'`iowrap.c |
|
2509 |
+ |
|
2503 | 2510 |
libclamav_internal_utils_nothreads_la-md5.lo: md5.c |
2504 | 2511 |
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_nothreads_la_CFLAGS) $(CFLAGS) -MT libclamav_internal_utils_nothreads_la-md5.lo -MD -MP -MF $(DEPDIR)/libclamav_internal_utils_nothreads_la-md5.Tpo -c -o libclamav_internal_utils_nothreads_la-md5.lo `test -f 'md5.c' || echo '$(srcdir)/'`md5.c |
2505 | 2512 |
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libclamav_internal_utils_nothreads_la-md5.Tpo $(DEPDIR)/libclamav_internal_utils_nothreads_la-md5.Plo |
... | ... |
@@ -688,7 +688,8 @@ void cache_add(unsigned char *md5, size_t size, cli_ctx *ctx) { |
688 | 688 |
} |
689 | 689 |
|
690 | 690 |
/* Hashes a file onto the provided buffer and looks it up the cache. |
691 |
- Returns CL_VIRUS if found, CL_CLEAN if not FIXME or an error */ |
|
691 |
+ Returns CL_VIRUS if found, CL_CLEAN if not FIXME or a recoverable error, |
|
692 |
+ and returns CL_EREAD if unrecoverable */ |
|
692 | 693 |
int cache_check(unsigned char *hash, cli_ctx *ctx) { |
693 | 694 |
fmap_t *map; |
694 | 695 |
size_t todo, at = 0; |
... | ... |
@@ -709,7 +710,10 @@ int cache_check(unsigned char *hash, cli_ctx *ctx) { |
709 | 709 |
return CL_EREAD; |
710 | 710 |
todo -= readme; |
711 | 711 |
at += readme; |
712 |
- cli_md5_update(&md5, buf, readme); |
|
712 |
+ if (cli_md5_update(&md5, buf, readme)) { |
|
713 |
+ cli_errmsg("cache_check: error reading while generating hash!\n"); |
|
714 |
+ return CL_EREAD; |
|
715 |
+ } |
|
713 | 716 |
} |
714 | 717 |
cli_md5_final(hash, &md5); |
715 | 718 |
ret = cache_lookup_hash(hash, map->len, ctx->engine->cache, ctx->recursion); |
716 | 719 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,60 @@ |
0 |
+/* |
|
1 |
+ * Copyright (C) 2012 Sourcefire, Inc. |
|
2 |
+ * |
|
3 |
+ * Authors: Dave Raynor |
|
4 |
+ * |
|
5 |
+ * This program is free software; you can redistribute it and/or modify |
|
6 |
+ * it under the terms of the GNU General Public License version 2 as |
|
7 |
+ * published by the Free Software Foundation. |
|
8 |
+ * |
|
9 |
+ * This program is distributed in the hope that it will be useful, |
|
10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
+ * GNU General Public License for more details. |
|
13 |
+ * |
|
14 |
+ * You should have received a copy of the GNU General Public License |
|
15 |
+ * along with this program; if not, write to the Free Software |
|
16 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
17 |
+ * MA 02110-1301, USA. |
|
18 |
+ * |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#include "iowrap.h" |
|
22 |
+ |
|
23 |
+#include <string.h> |
|
24 |
+ |
|
25 |
+#ifdef _WIN32 |
|
26 |
+#include <windows.h> |
|
27 |
+#include <excpt.h> |
|
28 |
+ |
|
29 |
+#ifndef STATUS_DEVICE_DATA_ERROR |
|
30 |
+#define STATUS_DEVICE_DATA_ERROR 0xC000009C |
|
31 |
+#endif |
|
32 |
+#endif |
|
33 |
+ |
|
34 |
+#ifdef _WIN32 |
|
35 |
+static int filter_memcpy(unsigned int code, struct _EXCEPTION_POINTERS *ep) { |
|
36 |
+ if ((code == EXCEPTION_IN_PAGE_ERROR) || (code == STATUS_DEVICE_DATA_ERROR)) { |
|
37 |
+ return EXCEPTION_EXECUTE_HANDLER; |
|
38 |
+ } |
|
39 |
+ return EXCEPTION_CONTINUE_SEARCH; |
|
40 |
+} |
|
41 |
+#endif |
|
42 |
+ |
|
43 |
+int cli_memcpy(void *target, const void *source, unsigned long size) |
|
44 |
+{ |
|
45 |
+ int ret = 0; |
|
46 |
+ |
|
47 |
+#ifdef _WIN32 |
|
48 |
+ __try { |
|
49 |
+#endif |
|
50 |
+ memcpy(target, source, size); |
|
51 |
+#ifdef _WIN32 |
|
52 |
+ } |
|
53 |
+ __except (filter_memcpy(GetExceptionCode(), GetExceptionInformation())) { |
|
54 |
+ ret = 1; |
|
55 |
+ } |
|
56 |
+#endif |
|
57 |
+ return ret; |
|
58 |
+} |
|
59 |
+ |
0 | 60 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,45 @@ |
0 |
+/* |
|
1 |
+ * Copyright (C) 2012 Sourcefire, Inc. |
|
2 |
+ * |
|
3 |
+ * Authors: Dave Raynor |
|
4 |
+ * |
|
5 |
+ * This program is free software; you can redistribute it and/or modify |
|
6 |
+ * it under the terms of the GNU General Public License version 2 as |
|
7 |
+ * published by the Free Software Foundation. |
|
8 |
+ * |
|
9 |
+ * This program is distributed in the hope that it will be useful, |
|
10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
+ * GNU General Public License for more details. |
|
13 |
+ * |
|
14 |
+ * You should have received a copy of the GNU General Public License |
|
15 |
+ * along with this program; if not, write to the Free Software |
|
16 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
17 |
+ * MA 02110-1301, USA. |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+#ifndef __IOWRAP_H |
|
21 |
+#define __IOWRAP_H |
|
22 |
+ |
|
23 |
+#if HAVE_CONFIG_H |
|
24 |
+#include "clamav-config.h" |
|
25 |
+#endif |
|
26 |
+ |
|
27 |
+#ifdef HAVE_UNISTD_H |
|
28 |
+#include <unistd.h> |
|
29 |
+#endif |
|
30 |
+ |
|
31 |
+#include <stdio.h> |
|
32 |
+#include <stdlib.h> |
|
33 |
+#ifdef _WIN32 |
|
34 |
+#include <windows.h> |
|
35 |
+#include <excpt.h> |
|
36 |
+#endif |
|
37 |
+ |
|
38 |
+/* |
|
39 |
+ * cli_memcpy is an io wrapper that will allow ClamAV to minimize impact of |
|
40 |
+ * adding SEH logic around map accesses where Windows might raise an error |
|
41 |
+ */ |
|
42 |
+int cli_memcpy(void *target, const void *source, unsigned long size); |
|
43 |
+ |
|
44 |
+#endif |
... | ... |
@@ -13,11 +13,14 @@ |
13 | 13 |
* This implementation is meant to be fast, but not as fast as possible. |
14 | 14 |
* Some known optimizations are not included to reduce source code size |
15 | 15 |
* and avoid compile-time configuration. |
16 |
+ * |
|
17 |
+ * Updated in 2012 to meet the needs of ClamAV. |
|
16 | 18 |
*/ |
17 | 19 |
|
18 | 20 |
#include <string.h> |
19 | 21 |
|
20 | 22 |
#include "md5.h" |
23 |
+#include "iowrap.h" |
|
21 | 24 |
|
22 | 25 |
/* |
23 | 26 |
* The basic MD5 functions. |
... | ... |
@@ -49,16 +52,16 @@ |
49 | 49 |
*/ |
50 | 50 |
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__) |
51 | 51 |
#define SET(n) \ |
52 |
- (*(const MD5_u32plus *)&ptr[(n) * 4]) |
|
52 |
+ (*(const MD5_u32plus *)&chunk[(n) * 4]) |
|
53 | 53 |
#define GET(n) \ |
54 | 54 |
SET(n) |
55 | 55 |
#else |
56 | 56 |
#define SET(n) \ |
57 | 57 |
(ctx->block[(n)] = \ |
58 |
- (MD5_u32plus)ptr[(n) * 4] | \ |
|
59 |
- ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ |
|
60 |
- ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ |
|
61 |
- ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) |
|
58 |
+ (MD5_u32plus)chunk[(n) * 4] | \ |
|
59 |
+ ((MD5_u32plus)chunk[(n) * 4 + 1] << 8) | \ |
|
60 |
+ ((MD5_u32plus)chunk[(n) * 4 + 2] << 16) | \ |
|
61 |
+ ((MD5_u32plus)chunk[(n) * 4 + 3] << 24)) |
|
62 | 62 |
#define GET(n) \ |
63 | 63 |
(ctx->block[(n)]) |
64 | 64 |
#endif |
... | ... |
@@ -66,12 +69,14 @@ |
66 | 66 |
/* |
67 | 67 |
* This processes one or more 64-byte data blocks, but does NOT update |
68 | 68 |
* the bit counters. There are no alignment requirements. |
69 |
+ * Returns NULL on a read error, or a pointer to the next byte if successful. |
|
69 | 70 |
*/ |
70 | 71 |
static const void *body(cli_md5_ctx *ctx, const void *data, unsigned long size) |
71 | 72 |
{ |
72 | 73 |
const unsigned char *ptr; |
73 | 74 |
MD5_u32plus a, b, c, d; |
74 | 75 |
MD5_u32plus saved_a, saved_b, saved_c, saved_d; |
76 |
+ unsigned char chunk[64]; |
|
75 | 77 |
|
76 | 78 |
ptr = data; |
77 | 79 |
|
... | ... |
@@ -86,6 +91,8 @@ static const void *body(cli_md5_ctx *ctx, const void *data, unsigned long size) |
86 | 86 |
saved_c = c; |
87 | 87 |
saved_d = d; |
88 | 88 |
|
89 |
+ if(cli_memcpy(chunk, ptr, 64)) |
|
90 |
+ return NULL; |
|
89 | 91 |
/* Round 1 */ |
90 | 92 |
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7) |
91 | 93 |
STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12) |
... | ... |
@@ -185,10 +192,11 @@ void cli_md5_init(cli_md5_ctx *ctx) |
185 | 185 |
ctx->hi = 0; |
186 | 186 |
} |
187 | 187 |
|
188 |
-void cli_md5_update(cli_md5_ctx *ctx, const void *data, unsigned long size) |
|
188 |
+int cli_md5_update(cli_md5_ctx *ctx, const void *data, unsigned long size) |
|
189 | 189 |
{ |
190 | 190 |
MD5_u32plus saved_lo; |
191 | 191 |
unsigned long used, free; |
192 |
+ int invalid = 0; |
|
192 | 193 |
|
193 | 194 |
saved_lo = ctx->lo; |
194 | 195 |
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) |
... | ... |
@@ -201,22 +209,27 @@ void cli_md5_update(cli_md5_ctx *ctx, const void *data, unsigned long size) |
201 | 201 |
free = 64 - used; |
202 | 202 |
|
203 | 203 |
if (size < free) { |
204 |
- memcpy(&ctx->buffer[used], data, size); |
|
205 |
- return; |
|
204 |
+ invalid = cli_memcpy(&ctx->buffer[used], data, size); |
|
205 |
+ return invalid; |
|
206 | 206 |
} |
207 | 207 |
|
208 |
- memcpy(&ctx->buffer[used], data, free); |
|
208 |
+ invalid = cli_memcpy(&ctx->buffer[used], data, free); |
|
209 |
+ if (invalid) |
|
210 |
+ return invalid; |
|
209 | 211 |
data = (const unsigned char *)data + free; |
210 | 212 |
size -= free; |
211 |
- body(ctx, ctx->buffer, 64); |
|
213 |
+ if (body(ctx, ctx->buffer, 64) == NULL) |
|
214 |
+ return 1; |
|
212 | 215 |
} |
213 | 216 |
|
214 | 217 |
if (size >= 64) { |
215 | 218 |
data = body(ctx, data, size & ~(unsigned long)0x3f); |
219 |
+ if (data == NULL) |
|
220 |
+ return 1; |
|
216 | 221 |
size &= 0x3f; |
217 | 222 |
} |
218 | 223 |
|
219 |
- memcpy(ctx->buffer, data, size); |
|
224 |
+ return cli_memcpy(ctx->buffer, data, size); |
|
220 | 225 |
} |
221 | 226 |
|
222 | 227 |
void cli_md5_final(unsigned char *result, cli_md5_ctx *ctx) |
... | ... |
@@ -5,6 +5,8 @@ |
5 | 5 |
* Written by Solar Designer <solar at openwall.com> in 2001, and placed |
6 | 6 |
* in the public domain. There's absolutely no warranty. |
7 | 7 |
* |
8 |
+ * Updated in 2012 to meet the needs of ClamAV. |
|
9 |
+ * |
|
8 | 10 |
* See md5.c for more information. |
9 | 11 |
*/ |
10 | 12 |
|
... | ... |
@@ -22,7 +24,7 @@ typedef struct { |
22 | 22 |
} cli_md5_ctx; |
23 | 23 |
|
24 | 24 |
extern void cli_md5_init(cli_md5_ctx *ctx); |
25 |
-extern void cli_md5_update(cli_md5_ctx *ctx, const void *data, unsigned long size); |
|
25 |
+extern int cli_md5_update(cli_md5_ctx *ctx, const void *data, unsigned long size); |
|
26 | 26 |
extern void cli_md5_final(unsigned char *result, cli_md5_ctx *ctx); |
27 | 27 |
|
28 | 28 |
#endif |
... | ... |
@@ -309,6 +309,7 @@ |
309 | 309 |
<ClCompile Include="..\libclamav\hashtab.c"/> |
310 | 310 |
<ClCompile Include="..\libclamav\htmlnorm.c"/> |
311 | 311 |
<ClCompile Include="..\libclamav\inflate64.c"/> |
312 |
+ <ClCompile Include="..\libclamav\iowrap.c"/> |
|
312 | 313 |
<ClCompile Include="..\libclamav\ishield.c"/> |
313 | 314 |
<ClCompile Include="..\libclamav\is_tar.c"/> |
314 | 315 |
<ClCompile Include="..\libclamav\jsparse\js-norm.c"/> |
... | ... |
@@ -135,6 +135,9 @@ |
135 | 135 |
<ClCompile Include="..\libclamav\inflate64.c"> |
136 | 136 |
<Filter>Source Files</Filter> |
137 | 137 |
</ClCompile> |
138 |
+ <ClCompile Include="..\libclamav\iowrap.c"> |
|
139 |
+ <Filter>Source Files</Filter> |
|
140 |
+ </ClCompile> |
|
138 | 141 |
<ClCompile Include="..\libclamav\is_tar.c"> |
139 | 142 |
<Filter>Source Files</Filter> |
140 | 143 |
</ClCompile> |
... | ... |
@@ -496,4 +499,4 @@ |
496 | 496 |
<Filter>Source Files\compat</Filter> |
497 | 497 |
</ClCompile> |
498 | 498 |
</ItemGroup> |
499 |
-</Project> |
|
500 | 499 |
\ No newline at end of file |
500 |
+</Project> |