From 636bfa81c164b24e70b8092cdb3687521ee0a599 Mon Sep 17 00:00:00 2001 From: "mccabe%netscape.com" Date: Wed, 12 May 1999 09:04:38 +0000 Subject: [PATCH] Allocate 1 extra space and nul-terminate the string given to XPT_NewString. Thanks to Jim Dunn for suggesting this fix. --- xpcom/libxpt/src/xpt_xdr.c | 5 ++++- xpcom/typelib/xpt/src/xpt_xdr.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xpcom/libxpt/src/xpt_xdr.c b/xpcom/libxpt/src/xpt_xdr.c index 47f660054c64..239f97c42421 100644 --- a/xpcom/libxpt/src/xpt_xdr.c +++ b/xpcom/libxpt/src/xpt_xdr.c @@ -274,12 +274,15 @@ XPT_NewString(PRUint16 length, char *bytes) if (!str) return NULL; str->length = length; - str->bytes = malloc(length); + /* Alloc one extra to store the trailing nul. */ + str->bytes = malloc(length + 1); if (!str->bytes) { XPT_DELETE(str); return NULL; } memcpy(str->bytes, bytes, length); + /* nul-terminate it. */ + str->bytes[length] = '\0'; return str; } diff --git a/xpcom/typelib/xpt/src/xpt_xdr.c b/xpcom/typelib/xpt/src/xpt_xdr.c index 47f660054c64..239f97c42421 100644 --- a/xpcom/typelib/xpt/src/xpt_xdr.c +++ b/xpcom/typelib/xpt/src/xpt_xdr.c @@ -274,12 +274,15 @@ XPT_NewString(PRUint16 length, char *bytes) if (!str) return NULL; str->length = length; - str->bytes = malloc(length); + /* Alloc one extra to store the trailing nul. */ + str->bytes = malloc(length + 1); if (!str->bytes) { XPT_DELETE(str); return NULL; } memcpy(str->bytes, bytes, length); + /* nul-terminate it. */ + str->bytes[length] = '\0'; return str; }