Mailing List Archive

[PATCH 1/1] log: do not print carriage return
From: Christian Hesse <mail@eworm.de>

Logging to stderr results in line endings being terminated with carriage
return (\r) and new line (\n). While this is fine for terminals it may
have undesired effects when running from crond and logging to syslog
or similar.

I run ssh from cron on an recent linux host. Viewing logs with
journalctl I see:

Sep 06 16:50:01 linux CROND[152575]: [96B blob data]

Adding switch --all for unprintable characters it shows:

Sep 06 16:50:01 linux CROND[152575]: (root) CMDOUT (Warning: Permanently
added '10.52.33.217' (ED25519) to the list of known hosts.^M)

Note the control character ^M. Removing the carriage return fixes this.

Signed-off-by: Christian Hesse <mail@eworm.de>
---
log.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log.c b/log.c
index d9c2d136..7e0737c4 100644
--- a/log.c
+++ b/log.c
@@ -462,7 +462,7 @@ do_log(LogLevel level, const char *fmt, va_list args)
tmp_handler(level, fmtbuf, log_handler_ctx);
log_handler = tmp_handler;
} else if (log_on_stderr) {
- snprintf(msgbuf, sizeof msgbuf, "%.*s\r\n",
+ snprintf(msgbuf, sizeof msgbuf, "%.*s\n",
(int)sizeof msgbuf - 3, fmtbuf);
(void)write(log_stderr_fd, msgbuf, strlen(msgbuf));
} else {
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: [PATCH 1/1] log: do not print carriage return [ In reply to ]
On Fri, 6 Sep 2019, Christian Hesse wrote:

> From: Christian Hesse <mail@eworm.de>
>
> Logging to stderr results in line endings being terminated with carriage
> return (\r) and new line (\n). While this is fine for terminals it may
> have undesired effects when running from crond and logging to syslog
> or similar.
>
> I run ssh from cron on an recent linux host. Viewing logs with
> journalctl I see:
>
> Sep 06 16:50:01 linux CROND[152575]: [96B blob data]
>
> Adding switch --all for unprintable characters it shows:
>
> Sep 06 16:50:01 linux CROND[152575]: (root) CMDOUT (Warning: Permanently
> added '10.52.33.217' (ED25519) to the list of known hosts.^M)
>
> Note the control character ^M. Removing the carriage return fixes this.

AFAIK we need the carriage return because the terminal may be in raw mode
and treating newline characters as advancing to the next line only.

-d
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: [PATCH 1/1] log: do not print carriage return [ In reply to ]
Damien Miller <djm@mindrot.org> on Sat, 2019/09/07 20:03:
> On Fri, 6 Sep 2019, Christian Hesse wrote:
>
> > From: Christian Hesse <mail@eworm.de>
> >
> > Logging to stderr results in line endings being terminated with carriage
> > return (\r) and new line (\n). While this is fine for terminals it may
> > have undesired effects when running from crond and logging to syslog
> > or similar.
> >
> > I run ssh from cron on an recent linux host. Viewing logs with
> > journalctl I see:
> >
> > Sep 06 16:50:01 linux CROND[152575]: [96B blob data]
> >
> > Adding switch --all for unprintable characters it shows:
> >
> > Sep 06 16:50:01 linux CROND[152575]: (root) CMDOUT (Warning: Permanently
> > added '10.52.33.217' (ED25519) to the list of known hosts.^M)
> >
> > Note the control character ^M. Removing the carriage return fixes this.
>
> AFAIK we need the carriage return because the terminal may be in raw mode
> and treating newline characters as advancing to the next line only.

Is this a general issue or for specific platforms only?

Anyway... This happens in combination with cronie only. Problem is that ssh
output is embedded in more text, stripping new line but keeping carriage
return. The latter needs to be stripped as well - I am already in contact with
cronie upstream.
--
main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH"
"CX:;",b;for(a/* Best regards my address: */=0;b=c[a++];)
putchar(b-1/(/* Chris cc -ox -xc - && ./x */b/42*2-3)*42);}