From mercurial at gmplib.org Wed Aug 27 08:09:45 2025 From: mercurial at gmplib.org (mercurial at gmplib.org) Date: Wed, 27 Aug 2025 08:09:45 +0200 Subject: [Gmp-commit] /var/hg/gmp: mini-gmp: Fix undefined NULL pointer arithmetic in ... Message-ID: details: /var/hg/gmp/rev/b06ade444025 changeset: 18487:b06ade444025 user: Niels M?ller date: Wed Aug 27 08:08:18 2025 +0200 description: mini-gmp: Fix undefined NULL pointer arithmetic in mpz_import. * mini-gmp/mini-gmp.c (mpz_import): Return early when count == 0, to avoid undefined behavior with pointer arithmetic, if the corresponding src pointer is NULL. Reported by Bruno Haible. diffstat: mini-gmp/ChangeLog | 6 ++++++ mini-gmp/mini-gmp.c | 5 +++++ 2 files changed, 11 insertions(+), 0 deletions(-) diffs (28 lines): diff -r f1c983debf6c -r b06ade444025 mini-gmp/ChangeLog --- a/mini-gmp/ChangeLog Thu Jun 19 09:27:33 2025 +0200 +++ b/mini-gmp/ChangeLog Wed Aug 27 08:08:18 2025 +0200 @@ -1,3 +1,9 @@ +2025-08-27 Niels M?ller + + * mini-gmp.c (mpz_import): Return early when count == 0, to avoid + undefined behavior with pointer arithmetic, if the corresponding + src pointer is NULL. Reported by Bruno Haible. + 2025-06-19 Niels M?ller * tests/t-gcd.c (test_one): Fix memory leak. diff -r f1c983debf6c -r b06ade444025 mini-gmp/mini-gmp.c --- a/mini-gmp/mini-gmp.c Thu Jun 19 09:27:33 2025 +0200 +++ b/mini-gmp/mini-gmp.c Wed Aug 27 08:08:18 2025 +0200 @@ -4515,6 +4515,11 @@ assert (order == 1 || order == -1); assert (endian >= -1 && endian <= 1); + if (count == 0) + { + r->_mp_size = 0; + return; + } if (endian == 0) endian = gmp_detect_endian ();