Skip to content

Commit d619596

Browse files
committed
logsrvd_conf_apply: Open server log after opening the event log
This way we avoid calling sudo_warn_set_conversation() until the point of no return. Found by the ZeroPath AI Security Engineer <https://zeropath.com>
1 parent 18123e3 commit d619596

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

logsrvd/logsrvd_conf.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,28 @@ logsrvd_conf_apply(struct logsrvd_config *config)
18251825
if (TAILQ_EMPTY(&config->relay.relays.addrs))
18261826
config->relay.store_first = false;
18271827

1828-
/* Open server log if specified. */
1828+
/* Open event log if specified. */
1829+
switch (config->eventlog.log_type) {
1830+
case EVLOG_SYSLOG:
1831+
openlog("sudo", 0, config->syslog.facility);
1832+
break;
1833+
case EVLOG_FILE:
1834+
config->logfile.stream = logsrvd_open_eventlog(config);
1835+
if (config->logfile.stream == NULL)
1836+
debug_return_bool(false);
1837+
break;
1838+
case EVLOG_NONE:
1839+
break;
1840+
default:
1841+
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
1842+
"cannot open unknown log type %d", config->eventlog.log_type);
1843+
break;
1844+
}
1845+
1846+
/*
1847+
* Open server log if specified.
1848+
* We do this last due to the sudo_warn_set_conversation() call.
1849+
*/
18291850
switch (config->server.log_type) {
18301851
case SERVER_LOG_SYSLOG:
18311852
sudo_warn_set_conversation(logsrvd_conv_syslog);
@@ -1850,24 +1871,6 @@ logsrvd_conf_apply(struct logsrvd_config *config)
18501871
break;
18511872
}
18521873

1853-
/* Open event log if specified. */
1854-
switch (config->eventlog.log_type) {
1855-
case EVLOG_SYSLOG:
1856-
openlog("sudo", 0, config->syslog.facility);
1857-
break;
1858-
case EVLOG_FILE:
1859-
config->logfile.stream = logsrvd_open_eventlog(config);
1860-
if (config->logfile.stream == NULL)
1861-
debug_return_bool(false);
1862-
break;
1863-
case EVLOG_NONE:
1864-
break;
1865-
default:
1866-
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
1867-
"cannot open unknown log type %d", config->eventlog.log_type);
1868-
break;
1869-
}
1870-
18711874
/*
18721875
* Update event and I/O log library config and install the new
18731876
* logsrvd config. We must not fail past this point or the event

0 commit comments

Comments
 (0)