Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 66f8687

Browse files
committed
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
1 parent ad77039 commit 66f8687

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/bin/psql/psqlscanslash.l

+2-2
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ evaluate_backtick(PsqlScanState state)
777777

778778
initPQExpBuffer(&cmd_output);
779779

780-
fd = popen(cmd, PG_BINARY_R);
780+
fd = popen(cmd, "r");
781781
if (!fd)
782782
{
783783
pg_log_error("%s: %m", cmd);
@@ -818,7 +818,7 @@ evaluate_backtick(PsqlScanState state)
818818
/* If no error, transfer result to output_buf */
819819
if (!error)
820820
{
821-
/* strip any trailing newline */
821+
/* strip any trailing newline (but only one) */
822822
if (cmd_output.len > 0 &&
823823
cmd_output.data[cmd_output.len - 1] == '\n')
824824
cmd_output.len--;

0 commit comments

Comments
 (0)