summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-10-28 14:35:53 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-10-28 14:35:53 -0400
commit504f963f76f0a5867b12cba8802e858cbfa53af9 (patch)
treeb38c78b63a63769a2ee1ceec29b44dda7231b8b5 /src
parent41c742a432427177e2ddd6ba434d555f8e6cf02b (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/16688-c649c7b69cd7e6f8@postgresql.org
Diffstat (limited to 'src')
-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 db7a1b9eead..8d62fe29faf 100644
--- a/src/bin/psql/psqlscanslash.l
+++ b/src/bin/psql/psqlscanslash.l
@@ -754,7 +754,7 @@ evaluate_backtick(PsqlScanState state)
initPQExpBuffer(&cmd_output);
- fd = popen(cmd, PG_BINARY_R);
+ fd = popen(cmd, "r");
if (!fd)
{
state->callbacks->write_error("%s: %s\n", cmd, strerror(errno));
@@ -795,7 +795,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--;