Skip to content

Commit aff0643

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 7978ad0 commit aff0643

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/bin/psql/psqlscan.l

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ evaluate_backtick(void)
17171717
17181718
initPQExpBuffer(&cmd_output);
17191719
1720-
fd = popen(cmd, PG_BINARY_R);
1720+
fd = popen(cmd, "r");
17211721
if (!fd)
17221722
{
17231723
psql_error("%s: %s\n", cmd, strerror(errno));
@@ -1758,7 +1758,7 @@ evaluate_backtick(void)
17581758
/* If no error, transfer result to output_buf */
17591759
if (!error)
17601760
{
1761-
/* strip any trailing newline */
1761+
/* strip any trailing newline (but only one) */
17621762
if (cmd_output.len > 0 &&
17631763
cmd_output.data[cmd_output.len - 1] == '\n')
17641764
cmd_output.len--;

0 commit comments

Comments
 (0)