From 31d8d4740ffb21c9898a21b5018c31e92af6935d Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Thu, 24 Feb 2022 20:58:18 +0100 Subject: [PATCH] Guard against reallocation failure in pg_regress realloc() will return NULL on a failed reallocation, so the destination pointer must be inspected to avoid null pointer dereference. Further, assigning the return value to the source pointer leak the allocation in the case of reallocation failure. Fix by using pg_realloc instead which has full error handling. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/9FC7E603-9246-4C62-B466-A39CFAF454AE@yesql.se --- src/test/regress/pg_regress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index e6f71c7582..db8427dd9b 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -774,7 +774,7 @@ fmtHba(const char *raw) const char *rp; char *wp; - wp = ret = realloc(ret, 3 + strlen(raw) * 2); + wp = ret = pg_realloc(ret, 3 + strlen(raw) * 2); *wp++ = '"'; for (rp = raw; *rp; rp++)