about summary refs log tree commit diff
path: root/src/string
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-04-18 17:38:35 -0400
committerRich Felker <dalias@aerifal.cx>2014-05-20 17:58:24 -0400
commite65bb40b30d4422f2d6ac2e1ae542e7879ddc13f (patch)
tree7ba618d94b09c38638f8ff92688c663a45011bf2 /src/string
parent84613196aad69fad6d1a2c1814fe0bfea67efbd7 (diff)
downloadmusl-e65bb40b30d4422f2d6ac2e1ae542e7879ddc13f.tar.gz
musl-e65bb40b30d4422f2d6ac2e1ae542e7879ddc13f.tar.xz
musl-e65bb40b30d4422f2d6ac2e1ae542e7879ddc13f.zip
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.

(cherry picked from commit 476cd1d96560aaf7f210319597556e7fbcd60469)
Diffstat (limited to 'src/string')
-rw-r--r--src/string/memmem.c2
-rw-r--r--src/string/strstr.c2
-rw-r--r--src/string/wcsstr.c2
3 files changed, 3 insertions, 3 deletions
diff --git a/src/string/memmem.c b/src/string/memmem.c
index a5a249f2..3b1ae183 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 915c0a22..cd069127 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 3e28e287..4caaef3c 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;
 	}