Re: com php-src: Throw warning when converting invalid string to GMP: ext/gmp/gmp.c ext/gmp/tests/003.phpt ext/gmp/tests/005.phpt
ext/gmp/tests/006.phpt ext/gmp/tests/010.phpt ext/gmp/tests/012.phpt ext/gmp/tests/013.phpt ext/gmp/tests/027.phpt ext/gmp/tests/029.phpt
ext/gmp/tests/030.phpt ext/gmp/tests/031.phpt ext/gmp/tests/032.phpt ext/gmp/tests/040.phpt ext/gmp/tests/gmp_nextprime.phpt

From: Date: Mon, 30 Dec 2013 21:49:00 +0000
Subject: Re: com php-src: Throw warning when converting invalid string to GMP: ext/gmp/gmp.c ext/gmp/tests/003.phpt ext/gmp/tests/005.phpt
ext/gmp/tests/006.phpt ext/gmp/tests/010.phpt ext/gmp/tests/012.phpt ext/gmp/tests/013.phpt ext/gmp/tests/027.phpt ext/gmp/tests/029.phpt
ext/gmp/tests/030.phpt ext/gmp/tests/031.phpt ext/gmp/tests/032.phpt ext/gmp/tests/040.phpt ext/gmp/tests/gmp_nextprime.phpt
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-75514@lists.php.net to get a copy of this message
Thanks Nikita. This helps :) -- Yasuo Ohgaki yohgaki@ohgaki.net On Mon, Dec 30, 2013 at 10:38 PM, Nikita Popov <nikic@php.net> wrote: > Commit: 5408f1e5a68fead0057c95df57cfb1ff0cc3fe81 > Author: Nikita Popov <nikic@php.net> Mon, 30 Dec 2013 14:37:32 > +0100 > Parents: feb4caad095313e905990359d93fde57c4c4c328 > Branches: PHP-5.6 master > > Link: > > http://git.php.net/?p=php-src.git;a=commitdiff;h=5408f1e5a68fead0057c95df57cfb1ff0cc3fe81 > > Log: > Throw warning when converting invalid string to GMP > > Changed paths: > M ext/gmp/gmp.c > M ext/gmp/tests/003.phpt > M ext/gmp/tests/005.phpt > M ext/gmp/tests/006.phpt > M ext/gmp/tests/010.phpt > M ext/gmp/tests/012.phpt > M ext/gmp/tests/013.phpt > M ext/gmp/tests/027.phpt > M ext/gmp/tests/029.phpt > M ext/gmp/tests/030.phpt > M ext/gmp/tests/031.phpt > M ext/gmp/tests/032.phpt > M ext/gmp/tests/040.phpt > M ext/gmp/tests/gmp_nextprime.phpt > > > Diff: > diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c > index 8835f05..c02b462 100644 > --- a/ext/gmp/gmp.c > +++ b/ext/gmp/gmp.c > @@ -718,14 +718,14 @@ static int convert_to_gmp(mpz_t gmpnumber, zval > *val, int base TSRMLS_DC) > { > switch (Z_TYPE_P(val)) { > case IS_LONG: > - case IS_BOOL: > - case IS_CONSTANT: { > + case IS_BOOL: { > mpz_set_si(gmpnumber, gmp_get_long(val)); > return SUCCESS; > } > case IS_STRING: { > char *numstr = Z_STRVAL_P(val); > int skip_lead = 0; > + int ret; > > if (Z_STRLEN_P(val) > 2) { > if (numstr[0] == '0') { > @@ -739,10 +739,18 @@ static int convert_to_gmp(mpz_t gmpnumber, zval > *val, int base TSRMLS_DC) > } > } > > - return mpz_set_str(gmpnumber, (skip_lead ? &numstr[2] : > numstr), base); > + ret = mpz_set_str(gmpnumber, (skip_lead ? &numstr[2] : > numstr), base); > + if (-1 == ret) { > + php_error_docref(NULL TSRMLS_CC, E_WARNING, > + "Unable to convert variable to GMP - > string is not an integer"); > + return FAILURE; > + } > + > + return SUCCESS; > } > default: > - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to > convert variable to GMP - wrong type"); > + php_error_docref(NULL TSRMLS_CC, E_WARNING, > + "Unable to convert variable to GMP - wrong type"); > return FAILURE; > } > } > diff --git a/ext/gmp/tests/003.phpt b/ext/gmp/tests/003.phpt > index 3798330..5179b73 100644 > --- a/ext/gmp/tests/003.phpt > +++ b/ext/gmp/tests/003.phpt > @@ -30,7 +30,8 @@ Check for number base recognition > printf("%s\n", gmp_strval($test[$i])); > } > ?> > ---EXPECT-- > +--EXPECTF-- > +Warning: gmp_init(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > 1234 > 1234 > 10011010010 > diff --git a/ext/gmp/tests/005.phpt b/ext/gmp/tests/005.phpt > index 4ae0cb7..79fd73e 100644 > --- a/ext/gmp/tests/005.phpt > +++ b/ext/gmp/tests/005.phpt > @@ -36,6 +36,8 @@ echo "Done\n"; > --EXPECTF-- > Warning: gmp_strval() expects at least 1 parameter, 0 given in %s on line > %d > NULL > + > +Warning: gmp_strval(): Unable to convert variable to GMP - string is not > an integer in %s on line %d > bool(false) > > Warning: gmp_strval() expects parameter 2 to be long, string given in %s > on line %d > diff --git a/ext/gmp/tests/006.phpt b/ext/gmp/tests/006.phpt > index 7407606..e1d9df6 100644 > --- a/ext/gmp/tests/006.phpt > +++ b/ext/gmp/tests/006.phpt > @@ -28,6 +28,8 @@ NULL > > Warning: gmp_sub() expects exactly 2 parameters, 1 given in %s on line %d > NULL > + > +Warning: gmp_sub(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > bool(false) > > Warning: gmp_sub() expects exactly 2 parameters, 3 given in %s on line %d > diff --git a/ext/gmp/tests/010.phpt b/ext/gmp/tests/010.phpt > index e3f85ec..12e7cad 100644 > --- a/ext/gmp/tests/010.phpt > +++ b/ext/gmp/tests/010.phpt > @@ -27,6 +27,8 @@ NULL > > Warning: gmp_mod() expects exactly 2 parameters, 1 given in %s on line %d > NULL > + > +Warning: gmp_mod(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > bool(false) > object(GMP)#%d (1) { > ["num"]=> > diff --git a/ext/gmp/tests/012.phpt b/ext/gmp/tests/012.phpt > index 8582ba1..8ca3471 100644 > --- a/ext/gmp/tests/012.phpt > +++ b/ext/gmp/tests/012.phpt > @@ -28,6 +28,8 @@ int(0) > int(-1) > int(1) > int(1) > + > +Warning: gmp_neg(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > int(0) > int(0) > int(0) > diff --git a/ext/gmp/tests/013.phpt b/ext/gmp/tests/013.phpt > index 06c2d81..bb35891 100644 > --- a/ext/gmp/tests/013.phpt > +++ b/ext/gmp/tests/013.phpt > @@ -22,6 +22,7 @@ var_dump(gmp_abs(array())); > echo "Done\n"; > ?> > --EXPECTF-- > +Warning: gmp_abs(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > string(1) "0" > string(1) "0" > string(1) "0" > @@ -31,7 +32,11 @@ string(1) "0" > string(21) "111111111111111111111" > string(21) "111111111111111111111" > string(1) "0" > + > +Warning: gmp_abs(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > string(1) "0" > + > +Warning: gmp_abs(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > string(1) "0" > > Warning: gmp_abs() expects exactly 1 parameter, 0 given in %s on line %d > diff --git a/ext/gmp/tests/027.phpt b/ext/gmp/tests/027.phpt > index 71204db..1efdc28 100644 > --- a/ext/gmp/tests/027.phpt > +++ b/ext/gmp/tests/027.phpt > @@ -25,7 +25,11 @@ int(1) > int(0) > int(1) > int(-1) > + > +Warning: gmp_sign(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > bool(false) > + > +Warning: gmp_init(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > int(0) > > Warning: gmp_sign() expects exactly 1 parameter, 2 given in %s on line %d > diff --git a/ext/gmp/tests/029.phpt b/ext/gmp/tests/029.phpt > index 1b86e47..9bc4010 100644 > --- a/ext/gmp/tests/029.phpt > +++ b/ext/gmp/tests/029.phpt > @@ -31,6 +31,8 @@ string(5) "40994" > string(3) "515" > string(4) "3333" > string(4) "4544" > + > +Warning: gmp_and(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > string(1) "0" > string(4) "1536" > string(15) "424703623692768" > diff --git a/ext/gmp/tests/030.phpt b/ext/gmp/tests/030.phpt > index 633af41..035f070 100644 > --- a/ext/gmp/tests/030.phpt > +++ b/ext/gmp/tests/030.phpt > @@ -31,6 +31,8 @@ string(6) "517363" > string(10) "2342341163" > string(2) "-1" > string(3) "-19" > + > +Warning: gmp_or(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > string(1) "0" > string(15) "987657876576252" > string(21) "987658441719689394144" > diff --git a/ext/gmp/tests/031.phpt b/ext/gmp/tests/031.phpt > index 90ce175..1e0c1b4 100644 > --- a/ext/gmp/tests/031.phpt > +++ b/ext/gmp/tests/031.phpt > @@ -26,6 +26,8 @@ echo "Done\n"; > --EXPECTF-- > string(2) "-1" > string(2) "-1" > + > +Warning: gmp_com(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > string(1) "0" > string(14) "-2394876545679" > string(3) "110" > diff --git a/ext/gmp/tests/032.phpt b/ext/gmp/tests/032.phpt > index 327c979..2b0d29a 100644 > --- a/ext/gmp/tests/032.phpt > +++ b/ext/gmp/tests/032.phpt > @@ -31,6 +31,8 @@ string(6) "476369" > string(10) "2342340648" > string(5) "-3334" > string(5) "-4563" > + > +Warning: gmp_xor(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > string(1) "0" > string(15) "987657876574716" > string(21) "987658017016065701376" > diff --git a/ext/gmp/tests/040.phpt b/ext/gmp/tests/040.phpt > index 9cc497e..29640ba 100644 > --- a/ext/gmp/tests/040.phpt > +++ b/ext/gmp/tests/040.phpt > @@ -37,7 +37,13 @@ NULL > > Warning: gmp_init(): Bad base for conversion: -1 (should be between 2 and > %d) in %s on line %d > bool(false) > + > +Warning: gmp_init(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > bool(false) > + > +Warning: gmp_init(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > bool(false) > + > +Warning: gmp_init(): Unable to convert variable to GMP - string is not an > integer in %s on line %d > string(1) "0" > Done > diff --git a/ext/gmp/tests/gmp_nextprime.phpt > b/ext/gmp/tests/gmp_nextprime.phpt > index 5683c8c..da89221 100644 > --- a/ext/gmp/tests/gmp_nextprime.phpt > +++ b/ext/gmp/tests/gmp_nextprime.phpt > @@ -34,6 +34,8 @@ string(6) "100003" > > Warning: gmp_nextprime(): Unable to convert variable to GMP - wrong type > in %s on line %d > string(1) "0" > + > +Warning: gmp_nextprime(): Unable to convert variable to GMP - string is > not an integer in %s on line %d > string(1) "0" > > Warning: gmp_nextprime(): Unable to convert variable to GMP - wrong type > in %s on line %d > > > -- > PHP CVS Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.cvs (#75514) next »