From 9484b67dfb0fc69326b4d94c2040751b205baa24 Mon Sep 17 00:00:00 2001 From: "Dr. Matthias St. Pierre" Date: Mon, 6 Jan 2020 02:38:14 +0100 Subject: [PATCH] Modify the add_seeds_stringlist() macro to fix a preprocessor error When OpenSSL is configured using `--with-rand-seed=devrandom`, the preprocessor reports the following error crypto/info.c:104:66: error: macro "add_seeds_stringlist" passed 3 arguments, but takes just 2 add_seeds_stringlist("random-device", { DEVRANDOM, NULL }); The reason why the preprocessor complains about three arguments being passed is that according to [1], balanced braces in macro arguments don't prevent the comma from acting as an argument separator: 3.3 Macro Arguments ... Parentheses within each argument must balance; a comma within such parentheses does not end the argument. However, there is no requirement for square brackets or braces to balance, and they do not prevent a comma from separating arguments. Also introduced an iteration pointer `p`, because `dev` is not an lvalue: crypto/info.c:78:41: error: lvalue required as increment operand for (; *dev != NULL; dev++) { [1] https://gcc.gnu.org/onlinedocs/cpp/Macro-Arguments.html Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/10762) --- crypto/info.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crypto/info.c b/crypto/info.c index 8e674fc30a..abba5437e2 100644 --- a/crypto/info.c +++ b/crypto/info.c @@ -72,14 +72,15 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings) do { \ add_seeds_string(label "("); \ { \ - const char *dev[] = strlist; \ + const char *dev[] = { strlist, NULL }; \ + const char **p; \ int first = 1; \ \ - for (; *dev != NULL; dev++) { \ + for (p = dev; *p != NULL; p++) { \ if (!first) \ OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \ first = 0; \ - OPENSSL_strlcat(seeds, *dev, sizeof(seeds)); \ + OPENSSL_strlcat(seeds, *p, sizeof(seeds)); \ } \ } \ OPENSSL_strlcat(seeds, ")", sizeof(seeds)); \ @@ -101,10 +102,10 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings) add_seeds_string("getrandom-syscall"); #endif #ifdef OPENSSL_RAND_SEED_DEVRANDOM - add_seeds_stringlist("random-device", { DEVRANDOM, NULL }); + add_seeds_stringlist("random-device", DEVRANDOM); #endif #ifdef OPENSSL_RAND_SEED_EGD - add_seeds_stringlist("EGD", { DEVRANDOM_EGD, NULL }); + add_seeds_stringlist("EGD", DEVRANDOM_EGD); #endif #ifdef OPENSSL_RAND_SEED_OS add_seeds_string("os-specific"); -- 2.25.1