Skip to content

Commit 682cc42

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix leak in gmp_export()
2 parents e076455 + fb246be commit 682cc42

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ext/gmp/gmp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ ZEND_FUNCTION(gmp_export)
971971
FETCH_GMP_ZVAL(gmpnumber, gmpnumber_arg, temp_a, 1);
972972

973973
if (mpz_sgn(gmpnumber) == 0) {
974-
RETURN_EMPTY_STRING();
974+
RETVAL_EMPTY_STRING();
975975
} else {
976976
size_t bits_per_word = size * 8;
977977
size_t count = (mpz_sizeinbase(gmpnumber, 2) + bits_per_word - 1) / bits_per_word;
@@ -980,7 +980,7 @@ ZEND_FUNCTION(gmp_export)
980980
mpz_export(ZSTR_VAL(out_string), NULL, order, size, endian, 0, gmpnumber);
981981
ZSTR_VAL(out_string)[ZSTR_LEN(out_string)] = '\0';
982982

983-
RETURN_NEW_STR(out_string);
983+
RETVAL_NEW_STR(out_string);
984984
}
985985

986986
FREE_GMP_TEMP(temp_a);

ext/gmp/tests/gmp_export.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ foreach ($export as $k => $test) {
5050

5151
var_dump($passed);
5252

53+
// Argument converted from int to GMP
54+
var_dump(bin2hex(gmp_export(0xff)));
55+
5356
// Invalid word sizes
5457
try {
5558
var_dump(gmp_export(123, -1));
@@ -76,6 +79,7 @@ try {
7679
?>
7780
--EXPECT--
7881
bool(true)
82+
string(2) "ff"
7983
gmp_export(): Argument #2 ($word_size) must be greater than or equal to 1
8084
gmp_export(): Argument #2 ($word_size) must be greater than or equal to 1
8185
gmp_export(): Argument #3 ($flags) cannot use multiple word order options

0 commit comments

Comments
 (0)