1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

Avoid Event Log entries with newlines in.

When logging an SSH_MSG_DISCONNECT, the log message has newlines in,
because it's also displayed in the GUI dialog box or on Plink's
standard error, where that makes some sense. But in the Event Log, all
messages should be one-liners: anything else makes the GUI list boxes
go weird, and also breaks convenient parsability of packet lot files.

So we turn newlines into spaces for Event Log purposes, which is
conveniently easy now that Event Log entries always go through
logging.c first.
This commit is contained in:
Simon Tatham 2018-10-13 17:23:29 +01:00
parent 1986ee2d9c
commit e966df071c

View File

@ -209,14 +209,8 @@ void logtraffic(LogContext *ctx, unsigned char c, int logmode)
}
}
/*
* Log an Event Log entry. Used in SSH packet logging mode, to copy
* the Event Log entries into the same log file as the packet data.
*/
void logevent(LogContext *ctx, const char *event)
static void logevent_internal(LogContext *ctx, const char *event)
{
if (!ctx)
return;
if (ctx->logtype == LGTYP_PACKETS || ctx->logtype == LGTYP_SSHRAW) {
logprintf(ctx, "Event Log: %s\r\n", event);
logflush(ctx);
@ -224,6 +218,38 @@ void logevent(LogContext *ctx, const char *event)
lp_eventlog(ctx->lp, event);
}
void logevent(LogContext *ctx, const char *event)
{
if (!ctx)
return;
/*
* Replace newlines in Event Log messages with spaces. (Sometimes
* the same message string is reused for the Event Log and a GUI
* dialog box; newlines are sometimes appropriate in the latter,
* but never in the former.)
*/
if (strchr(event, '\n') || strchr(event, '\r')) {
char *dup = dupstr(event);
char *p = dup, *q = dup;
while (*p) {
if (*p == '\r' || *p == '\n') {
do {
p++;
} while (*p == '\r' || *p == '\n');
*q++ = ' ';
} else {
*q++ = *p++;
}
}
*q = '\0';
logevent_internal(ctx, dup);
sfree(dup);
} else {
logevent_internal(ctx, event);
}
}
void logevent_and_free(LogContext *ctx, char *event)
{
logevent(ctx, event);