diff options
author | wtc%netscape.com <devnull@localhost> | 2001-09-11 22:22:16 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 2001-09-11 22:22:16 +0000 |
commit | 1e52c5a4792888ee1a1ae0fdb61b496a99627e6f (patch) | |
tree | 123aa9f48eb94224a431a64dc95eeec81c92d137 | |
parent | 2899346e4ab3815805a2f4570a8a2941aea0d98a (diff) | |
download | nspr-hg-1e52c5a4792888ee1a1ae0fdb61b496a99627e6f.tar.gz |
Bugzilla bug 96571: fixed the PL_strn* functions that may read beyond
the end of buffer if the buffer is not null-terminated.
Modified files: strchr.c strcstr.c strlen.c strpbrk.c strstr.c
-rw-r--r-- | lib/libc/src/strchr.c | 8 | ||||
-rw-r--r-- | lib/libc/src/strcstr.c | 4 | ||||
-rw-r--r-- | lib/libc/src/strlen.c | 2 | ||||
-rw-r--r-- | lib/libc/src/strpbrk.c | 4 | ||||
-rw-r--r-- | lib/libc/src/strstr.c | 4 |
5 files changed, 11 insertions, 11 deletions
diff --git a/lib/libc/src/strchr.c b/lib/libc/src/strchr.c index fd31222f..9ccae9a9 100644 --- a/lib/libc/src/strchr.c +++ b/lib/libc/src/strchr.c @@ -70,11 +70,11 @@ PL_strnchr(const char *s, char c, PRUint32 n) { if( (const char *)0 == s ) return (char *)0; - for( ; *s && n; s++, n-- ) + for( ; n && *s; s++, n-- ) if( *s == c ) return (char *)s; - if( ((char)0 == c) && ((char)0 == *s) && (n > 0)) return (char *)s; + if( ((char)0 == c) && (n > 0) && ((char)0 == *s) ) return (char *)s; return (char *)0; } @@ -86,10 +86,10 @@ PL_strnrchr(const char *s, char c, PRUint32 n) if( (const char *)0 == s ) return (char *)0; - for( p = s; *p && n; p++, n-- ) + for( p = s; n && *p; p++, n-- ) ; - if( ((char)0 == c) && ((char)0 == *p) && (n > 0) ) return (char *)p; + if( ((char)0 == c) && (n > 0) && ((char)0 == *p) ) return (char *)p; for( p--; p >= s; p-- ) if( *p == c ) diff --git a/lib/libc/src/strcstr.c b/lib/libc/src/strcstr.c index 2cb14cc8..7bf7d67d 100644 --- a/lib/libc/src/strcstr.c +++ b/lib/libc/src/strcstr.c @@ -86,7 +86,7 @@ PL_strncasestr(const char *big, const char *little, PRUint32 max) max -= ll; max++; - for( ; *big && max; big++, max-- ) + for( ; max && *big; big++, max-- ) /* obvious improvement available here */ if( 0 == PL_strncasecmp(big, little, ll) ) return (char *)big; @@ -105,7 +105,7 @@ PL_strncaserstr(const char *big, const char *little, PRUint32 max) ll = PL_strlen(little); - for( p = big; *p && max; p++, max-- ) + for( p = big; max && *p; p++, max-- ) ; p -= ll; diff --git a/lib/libc/src/strlen.c b/lib/libc/src/strlen.c index 7a797d93..30ed4403 100644 --- a/lib/libc/src/strlen.c +++ b/lib/libc/src/strlen.c @@ -59,7 +59,7 @@ PL_strnlen(const char *str, PRUint32 max) register const char *s; if( (const char *)0 == str ) return 0; - for( s = str; *s && max; s++, max-- ) + for( s = str; max && *s; s++, max-- ) ; return (PRUint32)(s - str); diff --git a/lib/libc/src/strpbrk.c b/lib/libc/src/strpbrk.c index 4174fd30..513ed2f6 100644 --- a/lib/libc/src/strpbrk.c +++ b/lib/libc/src/strpbrk.c @@ -75,7 +75,7 @@ PL_strnpbrk(const char *s, const char *list, PRUint32 max) if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0; - for( ; *s && max; s++, max-- ) + for( ; max && *s; s++, max-- ) for( p = list; *p; p++ ) if( *s == *p ) return (char *)s; @@ -91,7 +91,7 @@ PL_strnprbrk(const char *s, const char *list, PRUint32 max) if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0; - for( r = s; *r && max; r++, max-- ) + for( r = s; max && *r; r++, max-- ) ; for( r--; r >= s; r-- ) diff --git a/lib/libc/src/strstr.c b/lib/libc/src/strstr.c index 7d40ed3b..3f38a34f 100644 --- a/lib/libc/src/strstr.c +++ b/lib/libc/src/strstr.c @@ -86,7 +86,7 @@ PL_strnstr(const char *big, const char *little, PRUint32 max) max -= ll; max++; - for( ; *big && max; big++, max-- ) + for( ; max && *big; big++, max-- ) if( *little == *big ) if( 0 == PL_strncmp(big, little, ll) ) return (char *)big; @@ -105,7 +105,7 @@ PL_strnrstr(const char *big, const char *little, PRUint32 max) ll = PL_strlen(little); - for( p = big; *p && max; p++, max-- ) + for( p = big; max && *p; p++, max-- ) ; p -= ll; |