summaryrefslogtreecommitdiff
path: root/src/string
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-05 09:27:41 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-05 09:27:41 -0400
commit16675df793e896174230bdb6f99865c526830d3c (patch)
treeeb596dfb72e7ce283d2e186888a6b0c628d2585c /src/string
parent2f3d02cd83a46244c3f5a6fec851d7eded1376f4 (diff)
downloadmusl-16675df793e896174230bdb6f99865c526830d3c.tar.gz
musl-16675df793e896174230bdb6f99865c526830d3c.tar.bz2
musl-16675df793e896174230bdb6f99865c526830d3c.tar.xz
musl-16675df793e896174230bdb6f99865c526830d3c.zip
fix misaligned read on early string termination in strchr
this could actually cause rare crashes in the case where a short string is located at the end of a page and the following page is not readable, and in fact this was seen in gcc compiling certain files.
Diffstat (limited to 'src/string')
-rw-r--r--src/string/strchr.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/string/strchr.c b/src/string/strchr.c
index 2fe03386..d3563f18 100644
--- a/src/string/strchr.c
+++ b/src/string/strchr.c
@@ -15,8 +15,9 @@ char *strchr(const char *s, int c)
c = (unsigned char)c;
if (!c) return (char *)s + strlen(s);
- for (; ((uintptr_t)s & ALIGN) && *s; s++)
+ for (; ((uintptr_t)s & ALIGN); s++)
if (*(unsigned char *)s == c) return (char *)s;
+ else if (!*s) return 0;
k = ONES * c;
for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++);
for (s = (void *)w; *s; s++)