From 77d14126b1d37c9412ef285210d65751611d7ec4 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Thu, 22 Feb 2001 10:36:40 +0000 Subject: [PATCH] Safer bin2hex --- ext/standard/string.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 5cf17d9aef..8bedd35760 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -96,7 +96,7 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t * unsigned char *result = NULL; size_t i, j; - result = (char *) emalloc(oldlen * 2 * sizeof(char)); + result = (char *) emalloc(oldlen * 2 * sizeof(char) + 1); if(!result) { return result; } @@ -105,6 +105,7 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t * result[j++] = hexconvtab[old[i] >> 4]; result[j++] = hexconvtab[old[i] & 15]; } + result[j] = '\0'; if(newlen) *newlen = oldlen * 2 * sizeof(char); -- 2.40.0