0002-Must-check-return-value-of-malloc.patch.nocfbot

text/plain

Filename: 0002-Must-check-return-value-of-malloc.patch.nocfbot
Type: text/plain
Part: 1
Message: Re: SCRAM pass-through authentication for postgres_fdw
From 1c33c6b1e011f47c1d7decd5da6e952fad21ed6d Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 8 Jan 2025 11:37:17 +0100
Subject: [PATCH 2/3] Must check return value of malloc()

---
 src/interfaces/libpq/fe-connect.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 49f36f0e3d9..ebe272617e0 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -1807,6 +1807,8 @@ pqConnectOptions2(PGconn *conn)
 		len = pg_b64_dec_len(strlen(conn->scram_client_key));
 		conn->scram_client_key_len = len;
 		conn->scram_client_key_binary = malloc(len);
+		if (!conn->scram_client_key_binary)
+			goto oom_error;
 		pg_b64_decode(conn->scram_client_key, strlen(conn->scram_client_key),
 					  conn->scram_client_key_binary, len);
 	}
@@ -1818,6 +1820,8 @@ pqConnectOptions2(PGconn *conn)
 		len = pg_b64_dec_len(strlen(conn->scram_server_key));
 		conn->scram_server_key_len = len;
 		conn->scram_server_key_binary = malloc(len);
+		if (!conn->scram_server_key_binary)
+			goto oom_error;
 		pg_b64_decode(conn->scram_server_key, strlen(conn->scram_server_key),
 					  conn->scram_server_key_binary, len);
 	}
-- 
2.47.1