From: Stanislav Malyshev Date: Thu, 22 Feb 2001 10:36:40 +0000 (+0000) Subject: Safer bin2hex X-Git-Tag: php-4.0.5RC1~190 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77d14126b1d37c9412ef285210d65751611d7ec4;p=php Safer bin2hex --- 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);