summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2020-10-28 18:35:53 +0000
committerTom Lane2020-10-28 18:35:53 +0000
commit66f8687a8ff867f656de81e367314604d29dbd59 (patch)
treee6cb91cc23ccceb97c76c683f4335f38edf88e4b
parentad77039fad0f4128b0e4a05ddbf5dbc3ab5f3fa4 (diff)
Use mode "r" for popen() in psql's evaluate_backtick().
In almost all other places, we use plain "r" or "w" mode in popen() calls (the exceptions being for COPY data). This one has been overlooked (possibly because it's buried in a ".l" flex file?), but it's using PG_BINARY_R. Kensuke Okamura complained in bug #16688 that we fail to strip \r when stripping the trailing newline from a backtick result string. That's true enough, but we'd also fail to convert embedded \r\n cleanly, which also seems undesirable. Fixing the popen() mode seems like the best way to deal with this. It's been like this for a long time, so back-patch to all supported branches. Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/bin/psql/psqlscanslash.l4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/bin/psql/psqlscanslash.l b/src/bin/psql/psqlscanslash.l
index 2307491ba8..4dff84d627 100644
--- a/src/bin/psql/psqlscanslash.l
+++ b/src/bin/psql/psqlscanslash.l
@@ -777,7 +777,7 @@ evaluate_backtick(PsqlScanState state)
initPQExpBuffer(&cmd_output);
- fd = popen(cmd, PG_BINARY_R);
+ fd = popen(cmd, "r");
if (!fd)
{
pg_log_error("%s: %m", cmd);
@@ -818,7 +818,7 @@ evaluate_backtick(PsqlScanState state)
/* If no error, transfer result to output_buf */
if (!error)
{
- /* strip any trailing newline */
+ /* strip any trailing newline (but only one) */
if (cmd_output.len > 0 &&
cmd_output.data[cmd_output.len - 1] == '\n')
cmd_output.len--;