commit be28c77c6d493c74e87d5a1d05d58cb75a2a1585
parent 5533211e805d2f23374989762658770a72433528
Author: Joris Vink <joris@coders.se>
Date: Thu, 5 May 2016 15:28:59 +0200
Merge pull request #118 from wtfuzz/master
cast difference between pointers as unsigned in kore_mem_find()
Diffstat:
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/includes/kore.h b/includes/kore.h
@@ -514,7 +514,7 @@ int kore_snprintf(char *, size_t, int *, const char *, ...);
long long kore_strtonum(const char *, int, long long, long long, int *);
int kore_base64_encode(u_int8_t *, u_int32_t, char **);
int kore_base64_decode(char *, u_int8_t **, u_int32_t *);
-void *kore_mem_find(void *, size_t, void *, u_int32_t);
+void *kore_mem_find(void *, size_t, void *, size_t);
char *kore_text_trim(char *, size_t);
char *kore_read_line(FILE *, char *, size_t);
diff --git a/src/utils.c b/src/utils.c
@@ -482,20 +482,19 @@ kore_base64_decode(char *in, u_int8_t **out, u_int32_t *olen)
}
void *
-kore_mem_find(void *src, size_t slen, void *needle, u_int32_t len)
+kore_mem_find(void *src, size_t slen, void *needle, size_t len)
{
- u_int8_t *p, *end;
+ size_t pos;
- end = (u_int8_t *)src + slen;
- for (p = src; p < end; p++) {
- if (*p != *(u_int8_t *)needle)
+ for(pos = 0; pos < slen; pos++) {
+ if ( *((u_int8_t *)src + pos) != *(u_int8_t *)needle)
continue;
- if ((end - p) < len)
+ if ((slen - pos) < len)
return (NULL);
- if (!memcmp(p, needle, len))
- return (p);
+ if (!memcmp((u_int8_t *)src + pos, needle, len))
+ return ((u_int8_t *)src + pos);
}
return (NULL);