> On 2020-12-05 3:10 a.m., Joel Brobecker wrote: > > @@ -81,13 +133,26 @@ gdb_mpz::write (gdb::array_view buf, enum bfd_endian byte_order, > > mpz_add (exported_val.val, exported_val.val, neg_offset.val); > > } > > > > + /* Do the export into a buffer allocated by GMP itself; that way, > > + we can detect cases where BUF is not large enough to export > > + our value, and thus avoid a buffer overlow. Normally, this should > > + never happen, since we verified earlier that the buffer is large > > + enough to accomodate our value, but doing this allows us to be > > + extra safe with the export. > > + > > + After verification that the export behaved as expected, we will > > + copy the data over to BUF. */ > > + > > + size_t word_countp; > > + gdb::unique_xmalloc_ptr exported > > + (mpz_export (NULL, &word_countp, -1 /* order */, buf.size () /* size */, > > + endian, 0 /* nails */, exported_val.val)); > > + > > + gdb_assert (word_countp == 1); > > + > > /* Start by clearing the buffer, as mpz_export only writes as many > > - bytes as it needs (including none, if the value to export is zero. */ > > That comment is now stale. Indeed. Thanks for catching that. > Otherwise, that LGTM. Thanks Simon. The patch is now in, with the correction above (a copy of the patch is attached, for the record). -- Joel