From 1d8b48fd22dbfd613e25eb20a3c29acb6f2abe88 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 21 Mar 2019 15:23:51 +0000 Subject: [PATCH] pscp -scp: fix spurious newlines at end of filenames. Commit d07d7d66f introduced this bug: I replaced a manually grown string buffer with a strbuf, and failed to replicate the part where after I'd finished appending wire data to the string I removed the terminating \n. That string was used as the local file name, when downloading in SCP mode using a wildcard, so you'd get lots of local files whose names ended inconveniently in a newline character. Fixed by terminating the loop before we push the \n on to the strbuf in the first place. --- pscp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pscp.c b/pscp.c index 29b3e129..31336fe5 100644 --- a/pscp.c +++ b/pscp.c @@ -1380,11 +1380,13 @@ int scp_get_sink_action(struct scp_sink_action *act) if (ch == '\n') bump("Protocol error: Unexpected newline"); action = ch; - do { + while (1) { if (!ssh_scp_recv(&ch, 1)) bump("Lost connection"); + if (ch == '\n') + break; put_byte(act->buf, ch); - } while (ch != '\n'); + } switch (action) { case '\01': /* error */ with_stripctrl(san, act->buf->s)