From 08d8615ea73793831fda4563df8755062c093e2c Mon Sep 17 00:00:00 2001 From: "mccabe%netscape.com" Date: Tue, 4 May 1999 07:31:40 +0000 Subject: [PATCH] Check for consts > 0 before allocating record space for them. Fix to 5683, a malloc(0) bug; thanks to jlnance@inttek.com for catching this one. git-svn-id: svn://10.0.0.236/trunk@30094 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/libxpt/src/xpt_struct.c | 10 +++++++++- mozilla/xpcom/typelib/xpt/src/xpt_struct.c | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mozilla/xpcom/libxpt/src/xpt_struct.c b/mozilla/xpcom/libxpt/src/xpt_struct.c index ecdc2f32952..1856c666b89 100644 --- a/mozilla/xpcom/libxpt/src/xpt_struct.c +++ b/mozilla/xpcom/libxpt/src/xpt_struct.c @@ -37,9 +37,14 @@ static char *strdup(const char *c) static PRBool DoInterfaceDirectoryEntry(XPTCursor *cursor, XPTInterfaceDirectoryEntry *ide, PRUint16 index); + +#if 0 +/* currently unused */ static PRBool DoInterfaceDirectoryEntryIndex(XPTCursor *cursor, XPTInterfaceDirectoryEntry **idep); +#endif + static PRBool DoConstDescriptor(XPTCursor *cursor, XPTConstDescriptor *cd); @@ -486,9 +491,12 @@ DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp) goto error; } - if (mode == XPT_DECODE) + if (mode == XPT_DECODE && id->num_constants) { id->const_descriptors = XPT_CALLOC(id->num_constants * sizeof(XPTConstDescriptor)); + if (!id->const_descriptors) + goto error; + } for (i = 0; i < id->num_constants; i++) { if (!DoConstDescriptor(cursor, &id->const_descriptors[i])) { diff --git a/mozilla/xpcom/typelib/xpt/src/xpt_struct.c b/mozilla/xpcom/typelib/xpt/src/xpt_struct.c index ecdc2f32952..1856c666b89 100644 --- a/mozilla/xpcom/typelib/xpt/src/xpt_struct.c +++ b/mozilla/xpcom/typelib/xpt/src/xpt_struct.c @@ -37,9 +37,14 @@ static char *strdup(const char *c) static PRBool DoInterfaceDirectoryEntry(XPTCursor *cursor, XPTInterfaceDirectoryEntry *ide, PRUint16 index); + +#if 0 +/* currently unused */ static PRBool DoInterfaceDirectoryEntryIndex(XPTCursor *cursor, XPTInterfaceDirectoryEntry **idep); +#endif + static PRBool DoConstDescriptor(XPTCursor *cursor, XPTConstDescriptor *cd); @@ -486,9 +491,12 @@ DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp) goto error; } - if (mode == XPT_DECODE) + if (mode == XPT_DECODE && id->num_constants) { id->const_descriptors = XPT_CALLOC(id->num_constants * sizeof(XPTConstDescriptor)); + if (!id->const_descriptors) + goto error; + } for (i = 0; i < id->num_constants; i++) { if (!DoConstDescriptor(cursor, &id->const_descriptors[i])) {