Skip to content

Commit 88f46b1

Browse files
committed
Fix potential integer overflow in bin2hex
The code was already using safe_emalloc but did the multiplication in the first argument, thus making the use of safe_emalloc pretty useless. The *2 is now moved to the second argument.
1 parent 6b2b195 commit 88f46b1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *
131131
register unsigned char *result = NULL;
132132
size_t i, j;
133133

134-
result = (unsigned char *) safe_emalloc(oldlen * 2, sizeof(char), 1);
134+
result = (unsigned char *) safe_emalloc(oldlen, 2 * sizeof(char), 1);
135135

136136
for (i = j = 0; i < oldlen; i++) {
137137
result[j++] = hexconvtab[old[i] >> 4];

0 commit comments

Comments
 (0)