From c1787a74deeb8b0162684219136819a36a771e3e Mon Sep 17 00:00:00 2001 From: vignesh Date: Tue, 19 Nov 2019 19:48:38 +0530 Subject: [PATCH] initdb crash fix when createPQExpBuffer returns NULL pointer. createPQExpBuffer allocates memory and returns the pointer, there is a possibility that createPQExpBuffer can return NULL pointer in case of malloc failiure, but initdb's main function does not check this condition. Made changes to check and exit if createPQExpBuffer return's NULL pointer. --- src/bin/initdb/initdb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 88a261d..a428a91 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -3318,6 +3318,11 @@ main(int argc, char *argv[]) * Build up a shell command to tell the user how to start the server */ start_db_cmd = createPQExpBuffer(); + if (!start_db_cmd) + { + pg_log_error("out of memory"); + exit(1); + } /* Get directory specification used to start initdb ... */ strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path)); -- 1.8.3.1