postgres.git / summary / log / commit / refs
commit bc18487fe1cad25b36dbe06d33ae3cd046cddfeb
Author: Fujii Masao <fujii@postgresql.org>
Date: Wed Aug 19 03:38:16 2026 +0000
psql: Fix psql slash option leaks
psql_scan_slash_option() returns a malloc'd string, but \getresults,
\gset in pipeline mode, \restrict, and \unrestrict did not free it
after consuming or copying the value.
Free these option strings after use.
Backpatch to all supported versions. In v17 and older, only \restrict
and \unrestrict are affected, so those branches need only that part of
the fix.
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwEh3R3=1tx_a5=fTDJ+ycuwxWMEn6bG_Yt4B5P+hE7AVw@mail.gmail.com
Backpatch-through: 14
src/bin/psql/command.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 0f09fa95995..910d11e8aad 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -2361,10 +2361,12 @@ exec_command_restrict(PsqlScanState scan_state, bool active_branch,
if (opt == NULL || opt[0] == '\0')
{
pg_log_error("\\%s: missing required argument", cmd);
+ free(opt);
return PSQL_CMD_ERROR;
}
restrict_key = pstrdup(opt);
+ free(opt);
restricted = true;
}
else
@@ -2677,6 +2679,7 @@ exec_command_unrestrict(PsqlScanState scan_state, bool active_branch,
if (opt == NULL || opt[0] == '\0')
{
pg_log_error("\\%s: missing required argument", cmd);
+ free(opt);
return PSQL_CMD_ERROR;
}
@@ -2691,16 +2694,19 @@ exec_command_unrestrict(PsqlScanState scan_state, bool active_branch,
if (!restricted)
{
pg_log_error("\\%s: not currently in restricted mode", cmd);
+ free(opt);
return PSQL_CMD_ERROR;
}
else if (strcmp(opt, restrict_key) == 0)
{
pfree(restrict_key);
restricted = false;
+ free(opt);
}
else
{
pg_log_error("\\%s: wrong key", cmd);
+ free(opt);
return PSQL_CMD_ERROR;
}
}
[parent: b2e391aea588]