]> granicus.if.org Git - php/commitdiff
Safer bin2hex
authorStanislav Malyshev <stas@php.net>
Thu, 22 Feb 2001 10:36:40 +0000 (10:36 +0000)
committerStanislav Malyshev <stas@php.net>
Thu, 22 Feb 2001 10:36:40 +0000 (10:36 +0000)
ext/standard/string.c

index 5cf17d9aeff5da7a5d1fdd1a9d5386d721b04775..8bedd357609c35523c9a26b2739080a52526ae1a 100644 (file)
@@ -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);