git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@755 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2004/08/17 01:55:39... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Mon Aug 16 18:52:42 CEST 2004 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav: cli_memstr: fix bounds error (thanks to Nigel) and move to |
|
4 |
+ others.c |
|
5 |
+ |
|
1 | 6 |
Sun Aug 15 02:19:54 CEST 2004 (tk) |
2 | 7 |
---------------------------------- |
3 | 8 |
* freshclam: try all IP addresses provided by gethostbyname() in single |
... | ... |
@@ -473,3 +473,35 @@ int32_t cli_readint32(const char *buff) |
473 | 473 |
|
474 | 474 |
return ret; |
475 | 475 |
} |
476 |
+ |
|
477 |
+int cli_memstr(const char *haystack, int hs, const char *needle, int ns) |
|
478 |
+{ |
|
479 |
+ const char *pt, *hay; |
|
480 |
+ int n; |
|
481 |
+ |
|
482 |
+ |
|
483 |
+ if(hs < ns) |
|
484 |
+ return 0; |
|
485 |
+ |
|
486 |
+ if(haystack == needle) |
|
487 |
+ return 1; |
|
488 |
+ |
|
489 |
+ if(!memcmp(haystack, needle, ns)) |
|
490 |
+ return 1; |
|
491 |
+ |
|
492 |
+ pt = hay = haystack; |
|
493 |
+ n = hs; |
|
494 |
+ |
|
495 |
+ while((pt = memchr(hay, needle[0], n)) != NULL) { |
|
496 |
+ n = (int) pt - (int) hay; |
|
497 |
+ if(n < ns) |
|
498 |
+ break; |
|
499 |
+ |
|
500 |
+ if(!memcmp(pt, needle, ns)) |
|
501 |
+ return 1; |
|
502 |
+ |
|
503 |
+ hay = pt; |
|
504 |
+ } |
|
505 |
+ |
|
506 |
+ return 0; |
|
507 |
+} |
... | ... |
@@ -37,5 +37,6 @@ int32_t cli_readint32(const char *buff); |
37 | 37 |
char *cli_gentemp(const char *dir); |
38 | 38 |
unsigned int cli_rndnum(unsigned int max); |
39 | 39 |
char *cli_md5file(const char *filename); |
40 |
+int cli_memstr(const char *haystack, int hs, const char *needle, int ns); |
|
40 | 41 |
|
41 | 42 |
#endif |
... | ... |
@@ -141,25 +141,6 @@ static int cli_ddump(int desc, int offset, int size, const char *file) |
141 | 141 |
return 0; |
142 | 142 |
} |
143 | 143 |
|
144 |
-int cli_memstr(const char *haystack, int hs, const char *needle, int ns) |
|
145 |
-{ |
|
146 |
- const char *pt; |
|
147 |
- int n; |
|
148 |
- |
|
149 |
- if(!memcmp(haystack, needle, ns)) |
|
150 |
- return 1; |
|
151 |
- |
|
152 |
- pt = haystack; |
|
153 |
- n = hs; |
|
154 |
- while(n && (pt = memchr(pt, needle[0], n))) { |
|
155 |
- n--; |
|
156 |
- if(!memcmp(pt, needle, ns)) |
|
157 |
- return 1; |
|
158 |
- } |
|
159 |
- |
|
160 |
- return 0; |
|
161 |
-} |
|
162 |
- |
|
163 | 144 |
int cli_scanpe(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, int *arec, int *mrec) |
164 | 145 |
{ |
165 | 146 |
uint16_t e_magic; /* DOS signature ("MZ") */ |