diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2010-06-02 12:58:13 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2010-06-02 12:58:13 +0000 |
commit | 18e538e1cfd80829a25574b940c9ed27f6de3afd (patch) | |
tree | a31ce5a92cd90e0a50d1f13f621d9e51e4b2d38f /lib/libc/string/strnlen.c | |
parent | 52ede88f7bdb7c3fca55de6ec8df8f3999493364 (diff) |
Avoid using and end pointer since strnlen(string, -1) is legal
and would otherwise result in overflowing the end pointer and
cause strnlen() to return 0. OK sthen@
Diffstat (limited to 'lib/libc/string/strnlen.c')
-rw-r--r-- | lib/libc/string/strnlen.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/libc/string/strnlen.c b/lib/libc/string/strnlen.c index 0c6df381fc7..2dc7b4fb326 100644 --- a/lib/libc/string/strnlen.c +++ b/lib/libc/string/strnlen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strnlen.c,v 1.2 2010/05/21 06:57:45 chl Exp $ */ +/* $OpenBSD: strnlen.c,v 1.3 2010/06/02 12:58:12 millert Exp $ */ /* * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> @@ -23,10 +23,9 @@ size_t strnlen(const char *str, size_t maxlen) { - const char *cp, *ep; + const char *cp; - ep = str + maxlen; - for (cp = str; cp < ep && *cp != '\0'; cp++) + for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) ; return (size_t)(cp - str); |