]> granicus.if.org Git - php/commitdiff
Fix bug #52849 (GNU MP invalid version match).
authorAdam Harvey <aharvey@php.net>
Wed, 15 Sep 2010 10:51:55 +0000 (10:51 +0000)
committerAdam Harvey <aharvey@php.net>
Wed, 15 Sep 2010 10:51:55 +0000 (10:51 +0000)
NEWS
ext/gmp/gmp.c

diff --git a/NEWS b/NEWS
index f28420fcfa489cfb609280e0ab5b1137f087dd11..b0e5d77331b7b42d1d46a9d1bcded0d94c011aee 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@
 - Fixed possible crash in mssql_fetch_batch(). (Kalle)
 - Fixed inconsistent backlog default value (-1) in FPM on many systems. (fat)
 
+- Fixed bug #52849 (GNU MP invalid version match). (Adam)
 - Fixed bug #52843 (Segfault when optional parameters are not passed in to
   mssql_connect). (Felipe)
 - Fixed bug #52827 (cURL leaks handle and causes assertion error
index f53dcd652615fd43d1494962624eb08b735b0b42..8c453ab9b5d7b3038f4ec2ebef2d0266eee614cc 100644 (file)
@@ -316,6 +316,14 @@ static void _php_gmpnum_free(zend_rsrc_list_entry *rsrc TSRMLS_DC);
 #define GMP_ROUND_PLUSINF   1
 #define GMP_ROUND_MINUSINF  2
 
+/* The maximum base for input and output conversions is 62 from GMP 4.2
+ * onwards. */
+#if (__GNU_MP_VERSION >= 5) || (__GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2)
+#      define MAX_BASE 62
+#else
+#      define MAX_BASE 36
+#endif
+
 /* {{{ gmp_emalloc
  */
 static void *gmp_emalloc(size_t size)
@@ -753,12 +761,8 @@ ZEND_FUNCTION(gmp_init)
                return;
        }
 
-#if (__GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2)
-       if (base && (base < 2 || base > 62)) {
-#else
-       if (base && (base < 2 || base > 36)) {
-#endif
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %ld (should be between 2 and 36)", base);
+       if (base && (base < 2 || base > MAX_BASE)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %ld (should be between 2 and %d)", base, MAX_BASE);
                RETURN_FALSE;
        }
 
@@ -807,12 +811,15 @@ ZEND_FUNCTION(gmp_strval)
                return;
        }
 
-#if __GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2
-       if ((base < 2 && base > -2) || base > 62 || base < -36) {
+#if MAX_BASE == 62
+       /* Although the maximum base in general in GMP >= 4.2 is 62, mpz_get_str()
+        * is explicitly limited to -36 when dealing with negative bases. */
+       if ((base < 2 && base > -2) || base > MAX_BASE || base < -36) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %ld (should be between 2 and %d or -2 and -36)", base, MAX_BASE);
 #else
-       if (base < 2 || base > 36) {
+       if (base < 2 || base > MAX_BASE) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %ld (should be between 2 and %d)", base, MAX_BASE);
 #endif
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %ld", base);
                RETURN_FALSE;
        }