RFA: wrap mpz_export into gdb_mpz::safe_export...

Joel Brobecker
2020-11-29T15:46:06Z

Hello,

As discussed earlier this week when we discovered that we need to be
careful before calling mpz_export, the purpose of this patch series is
to introduce a new gdb_mpz method called safe_export that GDB can use
to make sure we don't have any buffer overrun. As it happens, you'll
see from patch #2 that I found a number of areas we could improve.

For the record, I didn't do the following, but I was thinking it would
be nice to poison mpz_export if we could. We can do that as a followup
patch, if we'd like, although I will likely need a bit of help doing so,
because I am not sure how to poison it for the entire GDB except the one
place where it's OK to use it. In the end, it sounds to me like Tom
wants to wrap GDB's usage of gmp into the gdb_mp[xxx] classes, and so,
once we have that, it seems unlikely that someone would unwittingly use
mpz_export directly.

Patch #1 is just something I noticed. Truth be told, I am kind of
second guessing myself on that one... Luckily, it's easy to just
drop it if it turns out I was wrong.

* [RFA 1/2] Fix TARGET_CHAR_BIT/HOST_CHAR_BIT confusion in gmp-utils.c
* [RFA 2/2] gmp-utils: protect gdb_mpz exports against out-of-range

The patches above were tested on x86_64-linux, with both the official
testsuite, as well as AdaCore's testsuite (just in case).

OK to push to master?

Thank you!
--
Joel