From 416240947b3d8de473e5e9c777ae941095382638 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Wed, 15 Sep 2010 10:51:55 +0000 Subject: [PATCH] Fix bug #52849 (GNU MP invalid version match). --- NEWS | 1 + ext/gmp/gmp.c | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index f28420fcfa..b0e5d77331 100644 --- 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 diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index f53dcd6526..8c453ab9b5 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -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; } -- 2.40.0