From 151faf6935d54efcc3b5bcf8e60419b490ac460d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 9 Mar 2004 09:56:33 +0000 Subject: JRA's recent strstr_m work really badly broke our string_sub code. For example: strstr_m("%v foo bar", "%v") would fail... only strstr_m("foo %v", "%v") could work. I wonder what else this broke... Fix is to move to using strncmp() inside the strstr_m function. Tested on ASCII only. Andrew Bartlett (This used to be commit 44d304f84c4ba5a832d5e3848ae0d04d5438ac15) --- source3/lib/util_str.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index cad0df48a4..7f3c30f61e 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1306,6 +1306,9 @@ char *strstr_m(const char *src, const char *findstr) char *s2; char *retp; + size_t findstr_len = 0; + size_t find_w_len; + /* Samba does single character findstr calls a *lot*. */ if (findstr[1] == '\0') return strchr_m(src, *findstr); @@ -1316,7 +1319,10 @@ char *strstr_m(const char *src, const char *findstr) for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) { if (*s == *findstr) { - if (strcmp(s, findstr) == 0) { + if (!findstr_len) + findstr_len = strlen(findstr); + + if (strncmp(s, findstr, findstr_len) == 0) { return (char *)s; } } @@ -1341,8 +1347,10 @@ char *strstr_m(const char *src, const char *findstr) return NULL; } + find_w_len = strlen_w(find_w); + for (p = src_w; (p = strchr_w(p, *find_w)) != NULL; p++) { - if (strcmp_w(p, find_w) == 0) + if (strncmp_w(p, find_w, find_w_len) == 0) break; } if (!p) { -- cgit