commit | 85e2b5f2fc29c83872a7f8772a45e23de9470064 | [log] [tgz] |
---|---|---|
author | H. Peter Anvin <hpa@zytor.com> | Thu Jul 15 16:42:19 2004 +0000 |
committer | H. Peter Anvin <hpa@zytor.com> | Thu Jul 15 16:42:19 2004 +0000 |
tree | b63f1cd700ed98c750d3ea73c21aaa44405c9e93 | |
parent | c21ffe42c5f7bcb737dd2871469c2623cfca83fd [diff] |
Fix possible segfault in strnlen()
diff --git a/klibc/strnlen.c b/klibc/strnlen.c index d0aa9cb..06b54c3 100644 --- a/klibc/strnlen.c +++ b/klibc/strnlen.c
@@ -7,7 +7,10 @@ size_t strnlen(const char *s, size_t maxlen) { const char *ss = s; - while(*ss && (maxlen > 0)) { + + /* Important: the maxlen test must precede the reference through ss; + since the byte beyond the maximum may segfault */ + while ((maxlen > 0) && *ss) { ss++; maxlen--; }