Bug #3062: dechex doesn't handle negative numbers

From: Date: Wed, 29 Dec 1999 02:40:25 +0000
Subject: Bug #3062: dechex doesn't handle negative numbers
Groups: php.dev 
Request: Send a blank email to php-dev+get-14124@lists.php.net to get a copy of this message
From: anderson@metrolink.com Operating system: FreeBSD PHP version: 3.0.12 PHP Bug Type: Misbehaving function Bug description: dechex doesn't handle negative numbers The function dechex() can be passed a negative number, which will create a negative index into a static array. This was discoverd when trying to manipulate IP addresses represented by integers. Any IP that has a first octet >127 will cause this to happen. Since integers are signed, I wonder what other areas might have a similar problem when trying to manipulate IP addresses in this way. Simple Example: print(dechex(-333333)); This fix seems to correct this instance of the problem, but I fear that there could possibly be undesirable side effect of doing this. *** php-3.0.12/functions/math.c Thu Apr 22 09:19:50 1999 --- php/functions/math.c Tue Dec 28 21:16:08 1999 *************** *** 424,430 **** static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; char *result, *ptr, *ret; int len, digit; ! long value; if (arg->type != IS_LONG || base < 2 || base > 36) { return empty_string; --- 424,430 ---- static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; char *result, *ptr, *ret; int len, digit; ! unsigned long value; if (arg->type != IS_LONG || base < 2 || base > 36) { return empty_string;

« previous php.dev (#14124) next »