diff options
author | Nikita Popov <nikic@php.net> | 2014-09-02 19:04:55 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2014-09-02 19:04:55 +0200 |
commit | 834daa455bc9c8cde178c6978dcb548119b038e8 (patch) | |
tree | d449a021285d104a31c88e26b636ac2856eec35c | |
parent | 7533243f0c78354b299bee5ee06702c66dd3a7cb (diff) | |
download | php-git-834daa455bc9c8cde178c6978dcb548119b038e8.tar.gz |
Fixed bug #50175
0x and 0b prefix is now only handled if either no base is given
or if the base is 16 (0x) or 2 (0b). Always handling it is incorrect
because 0x and 0b are perfectly valid numbers in other bases.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/gmp/gmp.c | 16 | ||||
-rw-r--r-- | ext/gmp/tests/bug50175.phpt | 18 |
3 files changed, 27 insertions, 9 deletions
@@ -22,6 +22,8 @@ PHP NEWS - GMP: . Fixed bug #67917 (Using GMP objects with overloaded operators can cause memory exhaustion). (Nikita) + . Fixed bug #50175 (gmp_init() results 0 on given base and number starting + with 0x or 0b). (Nikita) . Implemented gmp_import() and gmp_export(). (Leigh, Nikita) - MySQLi: diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index bf0f4f3fc7..619f1c39c3 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -773,15 +773,13 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC) int skip_lead = 0; int ret; - if (Z_STRLEN_P(val) > 2) { - if (numstr[0] == '0') { - if (numstr[1] == 'x' || numstr[1] == 'X') { - base = 16; - skip_lead = 1; - } else if (base != 16 && (numstr[1] == 'b' || numstr[1] == 'B')) { - base = 2; - skip_lead = 1; - } + if (Z_STRLEN_P(val) > 2 && numstr[0] == '0') { + if ((base == 0 || base == 16) && (numstr[1] == 'x' || numstr[1] == 'X')) { + base = 16; + skip_lead = 1; + } else if ((base == 0 || base == 2) && (numstr[1] == 'b' || numstr[1] == 'B')) { + base = 2; + skip_lead = 1; } } diff --git a/ext/gmp/tests/bug50175.phpt b/ext/gmp/tests/bug50175.phpt new file mode 100644 index 0000000000..0998e029c3 --- /dev/null +++ b/ext/gmp/tests/bug50175.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #50175: gmp_init() results 0 on given base and number starting with 0x or 0b +--FILE-- +<?php + +var_dump(gmp_init('0bcd', 16)); +var_dump(gmp_init('0xyz', 36)); + +?> +--EXPECTF-- +object(GMP)#%d (1) { + ["num"]=> + string(4) "3021" +} +object(GMP)#%d (1) { + ["num"]=> + string(5) "44027" +} |