From 7172b35aea09ee46e4e4c3c8cd9b665e9f25b418 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. git-svn-id: svn://10.0.0.236/trunk@31269 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/libxpt/src/xpt_xdr.c | 5 ++++- mozilla/xpcom/typelib/xpt/src/xpt_xdr.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mozilla/xpcom/libxpt/src/xpt_xdr.c b/mozilla/xpcom/libxpt/src/xpt_xdr.c index 47f660054c6..239f97c4242 100644 --- a/mozilla/xpcom/libxpt/src/xpt_xdr.c +++ b/mozilla/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/mozilla/xpcom/typelib/xpt/src/xpt_xdr.c b/mozilla/xpcom/typelib/xpt/src/xpt_xdr.c index 47f660054c6..239f97c4242 100644 --- a/mozilla/xpcom/typelib/xpt/src/xpt_xdr.c +++ b/mozilla/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; }