aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/generic/memmem.c
diff options
context:
space:
mode:
authorAndreas Jaeger <aj@suse.de>2000-05-18 05:35:38 +0000
committerAndreas Jaeger <aj@suse.de>2000-05-18 05:35:38 +0000
commit1261b97d10f60dfc7acc534a065bbe6ceef99f4f (patch)
treec25fe5bfa0e7dad407044c0519724702e874dca7 /sysdeps/generic/memmem.c
parentcc3f0ddb75ff6105a0fd869e6499c11e227bc787 (diff)
downloadglibc-1261b97d10f60dfc7acc534a065bbe6ceef99f4f.tar
glibc-1261b97d10f60dfc7acc534a065bbe6ceef99f4f.tar.gz
glibc-1261b97d10f60dfc7acc534a065bbe6ceef99f4f.tar.bz2
glibc-1261b97d10f60dfc7acc534a065bbe6ceef99f4f.zip
Update.
* sysdeps/generic/memmem.c (memmem): Check arguments to avoid possibly searching through the whole memory. Closes PR libc/1730, reported by Greg Hudson <ghudson@mit.edu>.
Diffstat (limited to 'sysdeps/generic/memmem.c')
-rw-r--r--sysdeps/generic/memmem.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sysdeps/generic/memmem.c b/sysdeps/generic/memmem.c
index 9e32f517b3..e9b270870a 100644
--- a/sysdeps/generic/memmem.c
+++ b/sysdeps/generic/memmem.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 96, 97, 98 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,96,97,98,2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -38,6 +38,11 @@ memmem (haystack, haystack_len, needle, needle_len)
the beginning of the string. */
return (void *) haystack;
+ /* Sanity check, otherwise the loop might search through the whole
+ memory. */
+ if (__builtin_expect (haystack_len < needle_len, 0))
+ return NULL;
+
for (begin = (const char *) haystack; begin <= last_possible; ++begin)
if (begin[0] == ((const char *) needle)[0] &&
!memcmp ((const void *) &begin[1],