Home GnuPG

cipher:pubkey: Fix non-use of flexible array member.

Description

cipher:pubkey: Fix non-use of flexible array member.

* cipher/pubkey.c (struct pk_single_data): Use 1 as the size.
(_gcry_pk_single_data_push): Use offsetof.
  • Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>

Details

Provenance
gniibeAuthored on Jun 14 2023, 10:11 AM
Parents
rC86fcf8292208: cipher:ecc: Support gcry_pk_hash_sign/verify for EdDSA.
Branches
Unknown
Tags
Unknown

Event Timeline

I doubt that we will ever be able to use the flexible array thingy. The old pattern has been used for nearly 50 years and replacing it will just introduce bugs.
Do you use offsetof for that reason?

I agree that the "future" won't come, ever. (for libgcrypt)

In my research around the variable length structure, the use of offsetof is considered good (for the correctness of the caluculation of the size).
offsetof has an issue for C++ (when it's not Plain-Old-Data structure), but not for C, at all.

Although it's not in the core part of the C language (like NULL or size_t), it has been supported among most C environment (even pre-ISO/non-ISO implementations).

For GCC, since GCC 4, we have __builtin_offsetof, and the calculation is reliable enough.