CVE-2023-28487 (Other, published 2023-03-16T01:15Z)
Description: value: Sudo before 1.9.13 does not escape control characters in sudoreplay output.
Severity: nan (CVSS v3 base score: 5.3)
Weakness: CWE-116 \u2014 Improper Encoding or Escaping of Output
The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved.
Repository: https://github.com/sudo-project/sudo
Files changed:
docs/sudoers.man.in
docs/sudoers.mdoc.in
docs/sudoreplay.man.in
docs/sudoreplay.mdoc.in
include/sudo_lbuf.h
lib/eventlog/eventlog.c
lib/iolog/iolog_json.c
lib/util/lbuf.c
lib/util/util.exp.in
plugins/sudoers/sudoreplay.c
Commit message: Escape control characters in log messages and "sudoreplay -l" output.
The log message contains user-controlled strings that could include
things like terminal control characters.  Space characters in the
command path are now also escaped.

Command line arguments that contain spaces are surrounded with
single quotes and any literal single quote or backslash characters
are escaped with a backslash.  This makes it possible to distinguish
multiple command line arguments from a single argument that contains
spaces.

Issue found by Matthieu Barjole and Victor Cutillas of Synacktiv
(https://synacktiv.com).


Vulnerable code:
date hostname progname: username : TTY=ttyname ; PWD=cwd ; \e
    USER=runasuser ; GROUP=runasgroup ; TSID=logid ; \e
The actual command that was executed.
and
\fIhostname\fR
fields are not present.
If the
\fIlog_year\fR
option is enabled,
the date will also include the year.
date hostname progname: username : TTY=ttyname ; PWD=cwd ; \e
    USER=runasuser ; GROUP=runasgroup ; TSID=logid ; \e
The actual command that was executed.
and
fields are not present.
If the
option is enabled,
the date will also include the year.
 * Copyright (c) 1994-1996, 1998-2021 Todd C. Miller <Todd.Miller@sudo.ws>
#define	LL_HOST_STR	"HOST="
#define	LL_TTY_STR	"TTY="
#define	LL_CHROOT_STR	"CHROOT="
#define	LL_CWD_STR	"PWD="
#define	LL_USER_STR	"USER="
#define	LL_GROUP_STR	"GROUP="
#define	LL_ENV_STR	"ENV="
#define	LL_CMND_STR	"COMMAND="
#define	LL_TSID_STR	"TSID="
#define	LL_EXIT_STR	"EXIT="
#define	LL_SIGNAL_STR	"SIGNAL="

    char *line = NULL, *evstr = NULL;
    size_t len = 0;
		if (asprintf(&line, "%s: %s", args->reason, args->errstr) == -1)
		    goto oom;
		if ((line = strdup(args->reason)) == NULL)
		    goto oom;
	debug_return_str(line);
     * Compute line length
    if (args->reason != NULL)
	len += strlen(args->reason) + 3;
    if (args->errstr != NULL)
	len += strlen(args->errstr) + 3;
    if (evlog->submithost != NULL && !evl_conf->omit_hostname)
	len += sizeof(LL_HOST_STR) + 2 + strlen(evlog->submithost);
    if (tty != NULL)
	len += sizeof(LL_TTY_STR) + 2 + strlen(tty);
    if (evlog->runchroot != NULL)
	len += sizeof(LL_CHROOT_STR) + 2 + strlen(evlog->runchroot);
    if (evlog->runcwd != NULL)
	len += sizeof(LL_CWD_STR) + 2 + strlen(evlog->runcwd);
    if (evlog->runuser != NULL)
	len += sizeof(LL_USER_STR) + 2 + strlen(evlog->runuser);
    if (evlog->rungroup != NULL)
	len += sizeof(LL_GROUP_STR) + 2 + strlen(evlog->rungroup);
    if (tsid != NULL) {
	len += sizeof(LL_TSID_STR) + 2 + strlen(tsid) + strlen(offsetstr);
    }
    if (evlog->env_add != NULL) {
	size_t evlen = 0;
	char * const *ep;

	for (ep = evlog->env_add; *ep != NULL; ep++)
	    evlen += strlen(*ep) + 1;
	if (evlen != 0) {
	    if ((evstr = malloc(evlen)) == NULL)
		goto oom;
	    ep = evlog->env_add;
	    if (strlcpy(evstr, *ep, evlen) >= evlen)
		goto toobig;
	    while (*++ep != NULL) {
		if (strlcat(evstr, " ", evlen) >= evlen ||
		    strlcat(evstr, *ep, evlen) >= evlen)
		    goto toobig;
	    }
	    len += sizeof(LL_ENV_STR) + 2 + evlen;
	}
    }
    if (evlog->command != NULL) {
	len += sizeof(LL_CMND_STR) - 1 + strlen(evlog->command);
	if (evlog->argv != NULL && evlog->argv[0] != NULL) {
	    for (i = 1; evlog->argv[i] != NULL; i++)
		len += strlen(evlog->argv[i]) + 1;
	}
	if (event_type == EVLOG_EXIT) {
	    if (evlog->signal_name != NULL)
		len += sizeof(LL_SIGNAL_STR) + 2 + strlen(evlog->signal_name);
	    if (evlog->exit_value != -1) {
		(void)snprintf(exit_str, sizeof(exit_str), "%d", evlog->exit_value);
		len += sizeof(LL_EXIT_STR) + 2 + strlen(exit_str);
	    }
	}
    }

    /*
     * Allocate and build up the line.
     */
    if ((line = malloc(++len)) == NULL)
	goto oom;
    line[0] = '\0';

	if (strlcat(line, args->reason, len) >= len ||
	    strlcat(line, args->errstr ? " : " : " ; ", len) >= len)
	    goto toobig;
	if (strlcat(line, args->errstr, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
	if (strlcat(line, LL_HOST_STR, len) >= len ||
	    strlcat(line, evlog->submithost, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
	if (strlcat(line, LL_TTY_STR, len) >= len ||
	    strlcat(line, tty, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
	if (strlcat(line, LL_CHROOT_STR, len) >= len ||
	    strlcat(line, evlog->runchroot, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
	if (strlcat(line, LL_CWD_STR, len) >= len ||
	    strlcat(line, evlog->runcwd, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
	if (strlcat(line, LL_USER_STR, len) >= len ||
	    strlcat(line, evlog->runuser, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
	if (strlcat(line, LL_GROUP_STR, len) >= len ||
	    strlcat(line, evlog->rungroup, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
	if (strlcat(line, LL_TSID_STR, len) >= len ||
	    strlcat(line, tsid, len) >= len ||
	    strlcat(line, offsetstr, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
    }
    if (evstr != NULL) {
	if (strlcat(line, LL_ENV_STR, len) >= len ||
	    strlcat(line, evstr, len) >= len ||
	    strlcat(line, " ; ", len) >= len)
	    goto toobig;
	free(evstr);
	evstr = NULL;
	if (strlcat(line, LL_CMND_STR, len) >= len)
	    goto toobig;
	if (strlcat(line, evlog->command, len) >= len)
	    goto toobig;
		if (strlcat(line, " ", len) >= len ||
		    strlcat(line, evlog->argv[i], len) >= len)
		    goto toobig;
		if (strlcat(line, " ; ", len) >= len ||
		    strlcat(line, LL_SIGNAL_STR, len) >= len ||
		    strlcat(line, evlog->signal_name, len) >= len)
		    goto toobig;
		if (strlcat(line, " ; ", len) >= len ||
		    strlcat(line, LL_EXIT_STR, len) >= len ||
		    strlcat(line, exit_str, len) >= len)
		    goto toobig;

    debug_return_str(line);
    free(evstr);
toobig:
    free(evstr);
    free(line);
    sudo_warnx(U_("internal error, %s overflow"), __func__);
    debug_return_str(NULL);
    /* Merge cmd and argv as sudoreplay expects. */
    if (evlog->command != NULL && evlog->argv != NULL && evlog->argv[0] != NULL) {
	size_t len, bufsize = strlen(evlog->command) + 1;
	char *cp, *buf;
	int ac;

	/* Skip argv[0], we use evlog->command instead. */
	for (ac = 1; evlog->argv[ac] != NULL; ac++)
	    bufsize += strlen(evlog->argv[ac]) + 1;

	if ((buf = malloc(bufsize)) == NULL) {
	    sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
	    goto done;
	}
	cp = buf;

	len = strlcpy(cp, evlog->command, bufsize);
	if (len >= bufsize)
	    sudo_fatalx(U_("internal error, %s overflow"), __func__);
	cp += len;
	bufsize -= len;

	for (ac = 1; evlog->argv[ac] != NULL; ac++) {
	    if (bufsize < 2)
		sudo_fatalx(U_("internal error, %s overflow"), __func__);
	    *cp++ = ' ';
	    bufsize--;

	    len = strlcpy(cp, evlog->argv[ac], bufsize);
	    if (len >= bufsize)
		sudo_fatalx(U_("internal error, %s overflow"), __func__);
	    cp += len;
	    bufsize -= len;
	}

	free(evlog->command);
	evlog->command = buf;
    }

	    rc = regexec(&sn->u.cmdre, evlog->command, 0, NULL, 0);
list_session(char *log_dir, regex_t *re, const char *user, const char *tty)
    int ret = -1;
    printf("%s : %s : ", timestr ? timestr : "invalid date", evlog->submituser);
    if (evlog->submithost != NULL)
	printf("HOST=%s ; ", evlog->submithost);
    if (evlog->ttyname != NULL)
	printf("TTY=%s ; ", evlog->ttyname);
    if (evlog->runchroot != NULL)
	printf("CHROOT=%s ; ", evlog->runchroot);
    if (evlog->runcwd != NULL || evlog->cwd != NULL)
	printf("CWD=%s ; ", evlog->runcwd ? evlog->runcwd : evlog->cwd);
    printf("USER=%s ; ", evlog->runuser);
    if (evlog->rungroup != NULL)
	printf("GROUP=%s ; ", evlog->rungroup);
    printf("TSID=%s ; COMMAND=%s\n", idstr, evlog->command);

    ret = 0;
		list_session(pathbuf, re, user, tty);

Fixed code:
Any control characters present in the log data are formatted in octal
with a leading
\(oq#\(cq
character.
For example, a horizontal tab is stored as
\(oq#011\(cq
and an embedded carriage return is stored as
\(oq#015\(cq.
In addition, space characters in the command path are stored as
\(oq#040\(cq.
Command line arguments that contain spaces are enclosed in single quotes
('').
This makes it possible to distinguish multiple command line arguments
from a single argument that contains spaces.
Literal single quotes and backslash characters
(\(oq\e\(cq)
in command line arguments are escaped with a backslash.
date hostname progname: username : TTY=ttyname ; CHROOT=chroot ; \e
    PWD=cwd ; USER=runasuser ; GROUP=runasgroup ; TSID=logid ; \e
chroot
The root directory that the command was run in, if one was specified.
.TP 14n
The actual command that was executed, including any command line arguments.
field is not present.
The
\fIhostname\fR
is only logged if the
\fIlog_host\fR
option is enabled.
The date does not include the year unless the
\fIlog_year\fR
option is enabled.
.TP 5n
4.\&
Any control characters present in the log data are formatted in octal
with a leading
.Ql #
character.
For example, a horizontal tab is stored as
.Ql #011
and an embedded carriage return is stored as
.Ql #015 .
In addition, space characters in the command path are stored as
.Ql #040 .
Command line arguments that contain spaces are enclosed in single quotes
.Pq '' .
This makes it possible to distinguish multiple command line arguments
from a single argument that contains spaces.
Literal single quotes and backslash characters
.Pq Ql \e
in command line arguments are escaped with a backslash.
date hostname progname: username : TTY=ttyname ; CHROOT=chroot ; \e
    PWD=cwd ; USER=runasuser ; GROUP=runasgroup ; TSID=logid ; \e
.It chroot
The root directory that the command was run in, if one was specified.
The actual command that was executed, including any command line arguments.
field is not present.
.It
The
is only logged if the
.Em log_host
option is enabled.
The date does not include the year unless the
option is enabled.
Any control characters present in the log data are formated in octal
with a leading
\(oq#\(cq
character.
For example, a horizontal tab is displayed as
\(oq#011\(cq
and an embedded carriage return is displayed as
\(oq#015\(cq.
.sp
Any control characters present in the log data are formatted in octal
with a leading
.Ql #
character.
For example, a horizontal tab is displayed as
.Ql #011
and an embedded carriage return is displayed as
.Ql #015 .
Space characters in the command name and arguments are also formatted in octal.
.Pp
/* Flags for sudo_lbuf_append_esc() */
#define LBUF_ESC_CNTRL	0x01
#define LBUF_ESC_BLANK	0x02
#define LBUF_ESC_QUOTE	0x04

sudo_dso_public bool sudo_lbuf_append_esc_v1(struct sudo_lbuf *lbuf, int flags, const char *fmt, ...) sudo_printflike(3, 4);
#define sudo_lbuf_append_esc sudo_lbuf_append_esc_v1
 * Copyright (c) 1994-1996, 1998-2023 Todd C. Miller <Todd.Miller@sudo.ws>
#include "sudo_lbuf.h"
    struct sudo_lbuf lbuf;
    sudo_lbuf_init(&lbuf, NULL, 0, NULL, 0);

		sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "%s: %s",
		    args->reason, args->errstr);
		sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "%s", args->reason);
	    if (sudo_lbuf_error(&lbuf))
		goto oom;
	debug_return_str(lbuf.buf);
     * Format the log line as an lbuf, escaping control characters in
     * octal form (#0nn).  Error checking (ENOMEM) is done at the end.
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "%s%s", args->reason,
	    args->errstr ? " : " : " ; ");
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "%s ; ", args->errstr);
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "HOST=%s ; ",
	    evlog->submithost);
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "TTY=%s ; ", tty);
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "CHROOT=%s ; ",
	    evlog->runchroot);
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "PWD=%s ; ",
	    evlog->runcwd);
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "USER=%s ; ",
	    evlog->runuser);
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "GROUP=%s ; ",
	    evlog->rungroup);
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "TSID=%s%s ; ", tsid,
	    offsetstr);
    }
    if (evlog->env_add != NULL && evlog->env_add[0] != NULL) {
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, "ENV=%s",
	    evlog->env_add[0]);
	for (i = 1; evlog->env_add[i] != NULL; i++) {
	    sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, " %s",
		evlog->env_add[i]);
	}
	sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL|LBUF_ESC_BLANK,
	    "COMMAND=%s", evlog->command);
		sudo_lbuf_append(&lbuf, " ");
		if (strchr(evlog->argv[i], ' ') != NULL) {
		    /* Wrap args containing spaces in single quotes. */
		    sudo_lbuf_append(&lbuf, "'");
		    sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL|LBUF_ESC_QUOTE,
			"%s", evlog->argv[i]);
		    sudo_lbuf_append(&lbuf, "'");
		} else {
		    /* Escape quotes here too for consistency. */
		    sudo_lbuf_append_esc(&lbuf,
			LBUF_ESC_CNTRL|LBUF_ESC_BLANK|LBUF_ESC_QUOTE,
			"%s", evlog->argv[i]);
		}
		sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, " ; SIGNAL=%s",
		    evlog->signal_name);
		(void)snprintf(exit_str, sizeof(exit_str), "%d",
		    evlog->exit_value);
		sudo_lbuf_append_esc(&lbuf, LBUF_ESC_CNTRL, " ; EXIT=%s",
		    exit_str);
    if (!sudo_lbuf_error(&lbuf))
	debug_return_str(lbuf.buf);
    sudo_lbuf_destroy(&lbuf);
/*
 * Escape a character in octal form (#0n) and store it as a string
 * in buf, which must have at least 6 bytes available.
 * Returns the length of buf, not counting the terminating NUL byte.
 */
static int
escape(unsigned char ch, char *buf)
{
    const int len = ch < 0100 ? (ch < 010 ? 3 : 4) : 5;

    /* Work backwards from the least significant digit to most significant. */
    switch (len) {
    case 5:
	buf[4] = (ch & 7) + '0';
	ch >>= 3;
	FALLTHROUGH;
    case 4:
	buf[3] = (ch & 7) + '0';
	ch >>= 3;
	FALLTHROUGH;
    case 3:
	buf[2] = (ch & 7) + '0';
	buf[1] = '0';
	buf[0] = '#';
	break;
    }
    buf[len] = '\0';

    return len;
}

/*
 * Parse the format and append strings, only %s and %% escapes are supported.
 * Any non-printable characters are escaped in octal as #0nn.
 */
bool
sudo_lbuf_append_esc_v1(struct sudo_lbuf *lbuf, int flags, const char *fmt, ...)
{
    unsigned int saved_len = lbuf->len;
    bool ret = false;
    const char *s;
    va_list ap;
    debug_decl(sudo_lbuf_append_esc, SUDO_DEBUG_UTIL);

    if (sudo_lbuf_error(lbuf))
	debug_return_bool(false);

#define should_escape(ch) \
    ((ISSET(flags, LBUF_ESC_CNTRL) && iscntrl((unsigned char)ch)) || \
    (ISSET(flags, LBUF_ESC_BLANK) && isblank((unsigned char)ch)))
#define should_quote(ch) \
    (ISSET(flags, LBUF_ESC_QUOTE) && (ch == '\'' || ch == '\\'))

    va_start(ap, fmt);
    while (*fmt != '\0') {
	if (fmt[0] == '%' && fmt[1] == 's') {
	    if ((s = va_arg(ap, char *)) == NULL)
		s = "(NULL)";
	    while (*s != '\0') {
		if (should_escape(*s)) {
		    if (!sudo_lbuf_expand(lbuf, sizeof("#0177") - 1))
			goto done;
		    lbuf->len += escape(*s++, lbuf->buf + lbuf->len);
		    continue;
		}
		if (should_quote(*s)) {
		    if (!sudo_lbuf_expand(lbuf, 2))
			goto done;
		    lbuf->buf[lbuf->len++] = '\\';
		    lbuf->buf[lbuf->len++] = *s++;
		    continue;
		}
		if (!sudo_lbuf_expand(lbuf, 1))
		    goto done;
		lbuf->buf[lbuf->len++] = *s++;
	    }
	    fmt += 2;
	    continue;
	}
	if (should_escape(*fmt)) {
	    if (!sudo_lbuf_expand(lbuf, sizeof("#0177") - 1))
		goto done;
	    if (*fmt == '\'') {
		lbuf->buf[lbuf->len++] = '\\';
		lbuf->buf[lbuf->len++] = *fmt++;
	    } else {
		lbuf->len += escape(*fmt++, lbuf->buf + lbuf->len);
	    }
	    continue;
	}
	if (!sudo_lbuf_expand(lbuf, 1))
	    goto done;
	lbuf->buf[lbuf->len++] = *fmt++;
    }
    ret = true;

done:
    if (!ret)
	lbuf->len = saved_len;
    if (lbuf->size != 0)
	lbuf->buf[lbuf->len] = '\0';
    va_end(ap);

    debug_return_bool(ret);
}

sudo_lbuf_append_esc_v1
#include "sudo_lbuf.h"
    if (evlog->argv != NULL && evlog->argv[0] != NULL) {
	for (i = 1; evlog->argv[i] != NULL; i++)
	    printf(" %s", evlog->argv[i]);
    }
static char *
expand_command(struct eventlog *evlog, char **newbuf)
{
    size_t len, bufsize = strlen(evlog->command) + 1;
    char *cp, *buf;
    int ac;
    debug_decl(expand_command, SUDO_DEBUG_UTIL);

    if (evlog->argv == NULL || evlog->argv[0] == NULL || evlog->argv[1] == NULL) {
	/* No arguments, we can use the command as-is. */
	*newbuf = NULL;
	debug_return_str(evlog->command);
    }

    /* Skip argv[0], we use evlog->command instead. */
    for (ac = 1; evlog->argv[ac] != NULL; ac++)
	bufsize += strlen(evlog->argv[ac]) + 1;

    if ((buf = malloc(bufsize)) == NULL)
	sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
    cp = buf;

    len = strlcpy(cp, evlog->command, bufsize);
    if (len >= bufsize)
	sudo_fatalx(U_("internal error, %s overflow"), __func__);
    cp += len;
    bufsize -= len;

    for (ac = 1; evlog->argv[ac] != NULL; ac++) {
	if (bufsize < 2)
	    sudo_fatalx(U_("internal error, %s overflow"), __func__);
	*cp++ = ' ';
	bufsize--;

	len = strlcpy(cp, evlog->argv[ac], bufsize);
	if (len >= bufsize)
	    sudo_fatalx(U_("internal error, %s overflow"), __func__);
	cp += len;
	bufsize -= len;
    }

    *newbuf = buf;
    debug_return_str(buf);
}

    char *tofree;
	    rc = regexec(&sn->u.cmdre, expand_command(evlog, &tofree),
		0, NULL, 0);
	    free(tofree);
list_session(struct sudo_lbuf *lbuf, char *log_dir, regex_t *re,
    const char *user, const char *tty)
    int i, ret = -1;
    sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "%s : %s : ",
	timestr ? timestr : "invalid date", evlog->submituser);
    if (evlog->submithost != NULL) {
	sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "HOST=%s ; ",
	    evlog->submithost);
    }
    if (evlog->ttyname != NULL) {
	sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "TTY=%s ; ",
	    evlog->ttyname);
    }
    if (evlog->runchroot != NULL) {
	sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "CHROOT=%s ; ",
	    evlog->runchroot);
    }
    if (evlog->runcwd != NULL || evlog->cwd != NULL) {
	sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "CWD=%s ; ",
	    evlog->runcwd ? evlog->runcwd : evlog->cwd);
    }
    sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "USER=%s ; ", evlog->runuser);
    if (evlog->rungroup != NULL) {
	sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "GROUP=%s ; ",
	    evlog->rungroup);
    }
    sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "TSID=%s ; ", idstr);

    /* 
     * If we have both command and argv from info.json we can escape
     * blanks in the the command and arguments.  If all we have is a
     * single string containing both the command and arguments we cannot.
     */
    if (evlog->argv != NULL) {
	/* Command plus argv from the info.json file. */
	sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL|LBUF_ESC_BLANK,
	    "COMMAND=%s", evlog->command);
	if (evlog->argv[0] != NULL) {
	    for (i = 1; evlog->argv[i] != NULL; i++) {
		sudo_lbuf_append(lbuf, " ");
		if (strchr(evlog->argv[i], ' ') != NULL) {
		    /* Wrap args containing spaces in single quotes. */
		    sudo_lbuf_append(lbuf, "'");
		    sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL|LBUF_ESC_QUOTE,
			"%s", evlog->argv[i]);
		    sudo_lbuf_append(lbuf, "'");
		} else {
		    /* Escape quotes here too for consistency. */
		    sudo_lbuf_append_esc(lbuf,
			LBUF_ESC_CNTRL|LBUF_ESC_BLANK|LBUF_ESC_QUOTE,
			"%s", evlog->argv[i]);
		}
	    }
	}
    } else {
	/* Single string from the legacy info file. */
	sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL, "COMMAND=%s",
	    evlog->command);
    }

    if (!sudo_lbuf_error(lbuf)) {
	puts(lbuf->buf);
	ret = 0;
    }
    lbuf->error = 0;
    lbuf->len = 0;
    struct sudo_lbuf lbuf;
    sudo_lbuf_init(&lbuf, NULL, 0, NULL, 0);

		list_session(&lbuf, pathbuf, re, user, tty);
    sudo_lbuf_destroy(&lbuf);