NSPR fixes for upcoming NSS update:

- Bug 347106: Need function to clear out PLArenas in PLArenaPools for security Patch contributed by Nelson Bolyard <nelson@bolyard.me>, r=wtc
- Bug 654436: Add the PR_ARRAY_SIZE macro. Replace the 'countof' macro in the sprintf.c test program with PR_ARRAY_SIZE. The patch is contributed by Konstantin Andreev <andreev@swemel.ru>. r=wtc. Modified Files: prtypes.h sprintf.c
This commit is contained in:
roytam1 2018-05-04 22:05:36 +08:00
parent e44dd98dbf
commit 3359ab400c
6 changed files with 53 additions and 27 deletions

View File

@ -260,6 +260,21 @@ PR_IMPLEMENT(void *) PL_ArenaGrow(
return newp;
}
static void ClearArenaList(PLArena *a, PRInt32 pattern)
{
for (; a; a = a->next) {
PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
a->avail = a->base;
PL_CLEAR_UNUSED_PATTERN(a, pattern);
}
}
PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern)
{
ClearArenaList(pool->first.next, pattern);
}
/*
* Free tail arenas linked after head, which may not be the true list head.
* Reset pool->current to point to head in case it pointed at a tail arena.
@ -274,12 +289,7 @@ static void FreeArenaList(PLArenaPool *pool, PLArena *head, PRBool reallyFree)
return;
#ifdef DEBUG
do {
PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
a->avail = a->base;
PL_CLEAR_UNUSED(a);
} while ((a = a->next) != 0);
a = *ap;
ClearArenaList(a, PL_FREE_PATTERN);
#endif
if (reallyFree) {

View File

@ -138,11 +138,12 @@ struct PLArenaPool {
#define PL_ARENA_MARK(pool) ((void *) (pool)->current->avail)
#define PR_UPTRDIFF(p,q) ((PRUword)(p) - (PRUword)(q))
#define PL_CLEAR_UNUSED_PATTERN(a, pattern) \
(PR_ASSERT((a)->avail <= (a)->limit), \
memset((void*)(a)->avail, (pattern), (a)->limit - (a)->avail))
#ifdef DEBUG
#define PL_FREE_PATTERN 0xDA
#define PL_CLEAR_UNUSED(a) (PR_ASSERT((a)->avail <= (a)->limit), \
memset((void*)(a)->avail, PL_FREE_PATTERN, \
(a)->limit - (a)->avail))
#define PL_CLEAR_UNUSED(a) PL_CLEAR_UNUSED_PATTERN((a), PL_FREE_PATTERN)
#define PL_CLEAR_ARENA(a) memset((void*)(a), PL_FREE_PATTERN, \
(a)->limit - (PRUword)(a))
#else

View File

@ -108,6 +108,11 @@ PR_EXTERN(void *) PL_ArenaGrow(
PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark);
/*
** memset contents of all arenas in pool to pattern
*/
PR_EXTERN(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern);
PR_END_EXTERN_C
#endif /* defined(PLARENAS_H) */

View File

@ -81,3 +81,8 @@ libVersionPoint;
PL_HashTableLookupConst;
PL_HashTableRawLookupConst;
;+} NSPR_4.0;
;+
;+NSPR_4.8.5 {
;+ global:
PL_ClearArenaPool;
;+} NSPR_4.1;

View File

@ -277,6 +277,13 @@
#define PR_MAX(x,y) ((x)>(y)?(x):(y))
#define PR_ABS(x) ((x)<0?-(x):(x))
/***********************************************************************
** MACROS: PR_ARRAY_SIZE
** DESCRIPTION:
** The number of elements in an array.
***********************************************************************/
#define PR_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
PR_BEGIN_EXTERN_C
/************************************************************************

View File

@ -56,8 +56,6 @@
#include <stdio.h>
#include <stdlib.h>
#define countof(a) (sizeof(a)/sizeof(a[0]))
static char sbuf[20000];
@ -121,15 +119,15 @@ static void TestI(void)
int f, s, n, p;
char fmt[20];
for (f = 0; f < countof(formats); f++) {
for (s = 0; s < countof(signs); s++) {
for (p = 0; p < countof(precs); p++) {
for (f = 0; f < PR_ARRAY_SIZE(formats); f++) {
for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
fmt[0] = '%';
fmt[1] = 0;
if (signs[s]) strcat(fmt, signs[s]);
if (precs[p]) strcat(fmt, precs[p]);
if (formats[f]) strcat(fmt, formats[f]);
for (n = 0; n < countof(nums); n++) {
for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
test_i(fmt, nums[n]);
}
}
@ -213,9 +211,9 @@ static void TestL(void)
int f, s, n, p;
char fmt[40], sfmt[40];
for (f = 0; f < countof(formats); f++) {
for (s = 0; s < countof(signs); s++) {
for (p = 0; p < countof(precs); p++) {
for (f = 0; f < PR_ARRAY_SIZE(formats); f++) {
for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
fmt[0] = '%';
fmt[1] = 0;
if (signs[s]) strcat(fmt, signs[s]);
@ -223,7 +221,7 @@ static void TestL(void)
strcpy(sfmt, fmt);
if (formats[f]) strcat(fmt, formats[f]);
if (sformats[f]) strcat(sfmt, sformats[f]);
for (n = 0; n < countof(nums); n++) {
for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
test_l(fmt, sfmt, nums[n]);
}
}
@ -336,9 +334,9 @@ static void TestLL(void)
int f, s, n, p;
char fmt[40], sfmt[40];
for (f = 0; f < countof(formats); f++) {
for (s = 0; s < countof(signs); s++) {
for (p = 0; p < countof(precs); p++) {
for (f = 0; f < PR_ARRAY_SIZE(formats); f++) {
for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
fmt[0] = '%';
fmt[1] = 0;
if (signs[s]) strcat(fmt, signs[s]);
@ -346,7 +344,7 @@ static void TestLL(void)
strcpy(sfmt, fmt);
if (formats[f]) strcat(fmt, formats[f]);
if (sformats[f]) strcat(sfmt, sformats[f]);
for (n = 0; n < countof(nums); n++) {
for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
test_ll(fmt, sfmt, nums[n]);
}
}
@ -424,15 +422,15 @@ static void TestS(void)
int f, s, n, p;
char fmt[40];
for (f = 0; f < countof(formats); f++) {
for (s = 0; s < countof(signs); s++) {
for (p = 0; p < countof(precs); p++) {
for (f = 0; f < PR_ARRAY_SIZE(formats); f++) {
for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
fmt[0] = '%';
fmt[1] = 0;
if (signs[s]) strcat(fmt+strlen(fmt), signs[s]);
if (precs[p]) strcat(fmt+strlen(fmt), precs[p]);
if (formats[f]) strcat(fmt+strlen(fmt), formats[f]);
for (n = 0; n < countof(strs); n++) {
for (n = 0; n < PR_ARRAY_SIZE(strs); n++) {
test_s(fmt, strs[n]);
}
}