Hi hackers, I found that there's a nullable pointer being passed to strcmp() and can make the server crash. It can be reproduced on the latest master branch by crafting an extension[1]. Patch for fixing it is attatched.
[1] https://github.com/higuoxing/guc_crash/tree/pg -- Best Regards, Xing
From dcd7a49190f0e19ba0a1e697cac45724450f6365 Mon Sep 17 00:00:00 2001 From: Xing Guo <higuox...@gmail.com> Date: Wed, 1 Nov 2023 16:41:49 +0800 Subject: [PATCH] Don't use strcmp() with nullable pointers. Passing a NULL pointer to strcmp() is an undefined behavior. It can make the PostgreSQL server crash. This patch helps fix it. --- src/backend/utils/misc/guc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 39d3775e80..b277c48925 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -5255,7 +5255,9 @@ get_explain_guc_options(int *num) { struct config_string *lconf = (struct config_string *) conf; - modified = (strcmp(lconf->boot_val, *(lconf->variable)) != 0); + modified = (lconf->boot_val == NULL || + *lconf->variable == NULL || + strcmp(lconf->boot_val, *(lconf->variable)) != 0); } break; -- 2.42.0