1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
From 476cd1d96560aaf7f210319597556e7fbcd60469 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Fri, 18 Apr 2014 17:38:35 -0400
Subject: [PATCH] fix false negatives with periodic needles in strstr, wcsstr,
and memmem
in cases where the memorized match range from the right factor
exceeded the length of the left factor, it was wrongly treated as a
mismatch rather than a match.
issue reported by Yves Bastide.
---
src/string/memmem.c | 2 +-
src/string/strstr.c | 2 +-
src/string/wcsstr.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/string/memmem.c b/src/string/memmem.c
index a5a249f..3b1ae18 100644
--- a/src/string/memmem.c
+++ b/src/string/memmem.c
@@ -120,7 +120,7 @@ static char *twoway_memmem(const unsigned char *h, const unsigned char *z, const
}
/* Compare left half */
for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--);
- if (k == mem) return (char *)h;
+ if (k <= mem) return (char *)h;
h += p;
mem = mem0;
}
diff --git a/src/string/strstr.c b/src/string/strstr.c
index 915c0a2..cd06912 100644
--- a/src/string/strstr.c
+++ b/src/string/strstr.c
@@ -130,7 +130,7 @@ static char *twoway_strstr(const unsigned char *h, const unsigned char *n)
}
/* Compare left half */
for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--);
- if (k == mem) return (char *)h;
+ if (k <= mem) return (char *)h;
h += p;
mem = mem0;
}
diff --git a/src/string/wcsstr.c b/src/string/wcsstr.c
index 3e28e28..4caaef3 100644
--- a/src/string/wcsstr.c
+++ b/src/string/wcsstr.c
@@ -84,7 +84,7 @@ static wchar_t *twoway_wcsstr(const wchar_t *h, const wchar_t *n)
}
/* Compare left half */
for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--);
- if (k == mem) return (wchar_t *)h;
+ if (k <= mem) return (wchar_t *)h;
h += p;
mem = mem0;
}
--
1.9.2
|