зеркало из https://github.com/mozilla/pjs.git
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
This commit is contained in:
Родитель
c43adffeaa
Коммит
51d7c86c9d
|
@ -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 )
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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-- )
|
||||
|
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче