Home GnuPG

build: Fix broken mlock detection


build: Fix broken mlock detection

* acinclude.m4 [GNUPG_CHECK_MLOCK]: Use size_t for the ptr test.

We need to be careful when casting a pointer to a long int: the
highest bit might be set, in which case the result is a negative number.

In this instance, it is fatal: we now take the modulus of that negative
number with regards to the page size, and subtract it from the page
size. So what should be a number that is smaller than the page size is
now larger than the page size.

As a consequence, we do not try to lock a 4096-byte block that is at the
page size boundary inside a malloc()ed block, but we try to do that
_outside_ the block.

Which means that we are not at all detecting whether mlock() is

This actually happened here, in the i686 MSYS2 build of libgcrypt.

Let's be very careful to case the pointer to an _unsigned_ value

Note: technically, we should cast the pointer to a size_t. But since
we only need the remainder modulo the page size (which is a power of
two) anyway, it does not matter whether we clip, say, a 64-bit size_t
to a 32-bit unsigned long. It does matter, though, whether we
mistakenly turn the remainder into a negative one.

  • Changed to use size_t for clarity.
  • Added ChangeLog entry.

Take care: Building for Windows using MSYS is not supported, please
use gcc and cross-compile.

  • Signed-off-by: Werner Koch <wk@gnupg.org>


Johannes Schindelin via Gcrypt-devel <gcrypt-devel@gnupg.org>Authored on Jun 16 2021, 10:07 AM
wernerCommitted on Jun 16 2021, 4:05 PM
rC585f153e1f74: cipher: Extend convenience OID mapping table for AES.