Commit Graph

525 Commits

Author SHA1 Message Date
Todd C. Miller
71997da168 Fix potential leak of evlog->runuser.
Also warn if we find an unexpected JSON type.
2021-02-02 10:27:27 -07:00
Todd C. Miller
eec4f42366 Allow getprogname() to succeed as long as __progname is present.
Also simplify the progname code so we only need a single implementation.
2021-02-02 11:20:53 -07:00
Todd C. Miller
1e3cecc608 Add initial fuzzers to be used by oss-fuzz.
These are not yet hooked up to the sudo build.
2021-02-01 15:17:57 -07:00
Todd C. Miller
4cd6350cad Fix crashes trying to parse invalid JSON.
Found locally using libfuzzer/oss-fuzz.
2021-01-30 16:16:23 -07:00
Todd C. Miller
de82d08e70 Plug memory leak if a key is listed more than once in the log.json file. 2021-01-30 16:15:24 -07:00
Todd C. Miller
5dc297d300 Fix crash when file does not exist. 2021-01-30 14:04:05 -07:00
Todd C. Miller
8781560e1b In json_stack_push() treat stack exhaustion like memory allocation failure.
Return NULL instead of treating as a fatal error.
This should make life a little easier for oss-fuzz.
2021-01-29 09:23:51 -07:00
Fabrice Fontaine
c05fe93669 lib/eventlog/Makefile.in: fix static build without closefrom
Since version 1.9.4 and
bd1ca79cca,
when closefrom is not available, libsudo_eventlog.a depends on
libsudo_util.a. So reflect this dependency in the libtool file to avoid
the following static build failure of logsrvd:

/bin/bash ../libtool --tag=disable-static --mode=link /home/buildroot/autobuild/instance-1/output-1/host/bin/powerpc-linux-gcc -o sudo_logsrvd logsrv_util.o iolog_writer.o logsrvd.o logsrvd_conf.o -static -Wl,--enable-new-dtags -Wl,-z,relro    ../lib/iolog/libsudo_iolog.la ../lib/eventlog/libsudo_eventlog.la ../lib/logsrv/liblogsrv.la
/bin/bash ../libtool --tag=disable-static --mode=link /home/buildroot/autobuild/instance-1/output-1/host/bin/powerpc-linux-gcc -o sudo_sendlog logsrv_util.o sendlog.o -static -Wl,--enable-new-dtags -Wl,-z,relro    ../lib/iolog/libsudo_iolog.la ../lib/eventlog/libsudo_eventlog.la ../lib/logsrv/liblogsrv.la
libtool: link: /home/buildroot/autobuild/instance-1/output-1/host/bin/powerpc-linux-gcc -o sudo_logsrvd logsrv_util.o iolog_writer.o logsrvd.o logsrvd_conf.o -static -Wl,--enable-new-dtags -Wl,-z -Wl,relro  ../lib/iolog/.libs/libsudo_iolog.a /home/buildroot/autobuild/instance-1/output-1/build/sudo-1.9.5p1/lib/util/.libs/libsudo_util.a -lpthread -lz ../lib/eventlog/.libs/libsudo_eventlog.a ../lib/logsrv/.libs/liblogsrv.a
/home/buildroot/autobuild/instance-1/output-1/host/opt/ext-toolchain/bin/../lib/gcc/powerpc-buildroot-linux-uclibc/8.3.0/../../../../powerpc-buildroot-linux-uclibc/bin/ld: ../lib/eventlog/.libs/libsudo_eventlog.a(eventlog.o): in function `send_mail.constprop.1':
eventlog.c:(.text+0x149c): undefined reference to `sudo_closefrom'
collect2: error: ld returned 1 exit status

Fixes:
 - http://autobuild.buildroot.org/results/515b45f876fa9de03c9235f86017f4dc10eb3b54

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2021-01-22 07:00:18 -07:00
Todd C. Miller
d98dd5f98d Fix setprogname() emulation on systems without it.
For fully-qualified paths, store the string starting after the last slash,
not at the slash itself.
2021-01-15 15:25:44 -07:00
Todd C. Miller
4e11bc0e26 Suppress PVS Studio false positives. 2021-01-06 14:27:09 -07:00
Todd C. Miller
84b3a1dae1 Remove the --force option from the cppcheck args, it causes errors. 2021-01-06 13:01:09 -07:00
Todd C. Miller
9e068c15e0 Add setprogname(3) for those without it. 2021-01-06 13:01:09 -07:00
Todd C. Miller
71339c574f Check the return value of fcntl() when setting FD_CLOEXEC.
This should never fail unless the fd is invalid.
Problem reported by Matthias Gerstner of SUSE.
2021-01-06 10:16:00 -07:00
Todd C. Miller
b132def0b1 For sudo, only allow "sudo" or "sudoedit" as the program name.
The program name is also used when matching Debug lines in sudo.conf.
We don't want the user to be able to influence sudo.conf Debug matching.
The string "sudoedit" is treated the same as "sudo" in sudo.conf.
Problem reported by Matthias Gerstner of SUSE.
2021-01-06 10:16:00 -07:00
Todd C. Miller
6e1986e915 Remove #ifdefs around code using pread(3) and pwrite(3). 2021-01-02 10:43:34 -07:00
Todd C. Miller
06bfbecd64 Add emulation of pread(3) and pwrite(3) for systems without them.
This makes it possible to remove some ugly #ifdefs and only affects
very old systems.
2021-01-02 10:43:34 -07:00
Todd C. Miller
8617833385 Minor fixes pointed out by cppcheck.
Also add compareBoolExpressionWithInt to suppression list.
2021-01-02 10:43:34 -07:00
Todd C. Miller
9547755c3f Fix deregistration of a callback that is not at the head of the list.
The SLIST_FOREACH_PREVPTR macro doesn't work the way I thought it did.
Just store our own prev pointer and use that instead.
2020-12-30 07:09:35 -07:00
Todd C. Miller
567e5167d1 Don't assume that just because command is non-NULL, argv is non-NULL. 2020-12-04 13:48:16 -07:00
Todd C. Miller
e22817e3ab Fix build when configured using --without-sendmail
Bug #947
2020-11-30 13:18:12 -07:00
Todd C. Miller
4a6ca4ba22 Fix calling sudo_conf_read() multiple times with different conf_types.
The change to reinitialize the configuration data when sudo_conf_read()
is called again didn't take into account that sudo calls sudo_conf_read()
twice--once for the debug info and once for everything else.
2020-11-18 09:36:05 -07:00
Todd C. Miller
deb217adf9 On SIGHUP, deregister the old debug instance before registering a new one.
Otherwise, if debugging is enabled we will get an extra log instance
each time sudo_logsrvd reeives SIGHUP which results in duplicate
lines in the debug log.
2020-11-10 19:36:55 -07:00
Todd C. Miller
9779009fae Add info_msgs to AlertMessage and populate it.
This lets us log eventlog info along with the alert if it is available.
2020-11-09 17:15:11 -07:00
Todd C. Miller
0dd4c5797a For logsrvd AlertMessages, evlog will be NULL. 2020-11-06 14:40:54 -07:00
Todd C. Miller
444ca3789e Append errstr to reason for alert and reject events if specified.
Previously, we logged the error string separately but this is
not consistent with how it is logged in other formats.
2020-11-06 13:09:21 -07:00
Todd C. Miller
a9cad13b11 Use struct eventlog *evlog, not struct eventlog *details. 2020-11-09 16:52:21 -07:00
Todd C. Miller
e0c2635fb3 Apply Google inclusive language guidelines.
Also replace backwards with backward.
2020-10-30 10:15:30 -06:00
Todd C. Miller
1910b1924f Test eventlog_writeln() when word wrap is disabled. 2020-10-28 13:47:40 -06:00
Todd C. Miller
8c43eeb293 For JSON logs, write the most important log elements first.
This is important for syslog where the record could be truncated.
2020-10-27 16:28:16 -06:00
Todd C. Miller
6bc729aa36 Support "minimal" JSON which skips all non-essention whitespace.
This replaces the old "compact" mode which is only used for syslog.
2020-10-27 13:26:22 -06:00
Todd C. Miller
34c1651514 Check for fdopen(3) failure in send_mail(). 2020-10-26 21:23:36 -06:00
Todd C. Miller
fdae4bdbbb Add support for file log line wrapping in libeventlog. 2020-10-26 16:16:46 -06:00
Todd C. Miller
d899fe5936 Use real setters for the eventlog config.
This makes it possible to have a base config that the callers can
modify instead of replacing the config wholesale.
2020-10-26 16:10:42 -06:00
Todd C. Miller
39b540ff33 Log the short version of the tty in sudoers-format logs.
This is consistent with historical practice.
2020-10-26 16:10:40 -06:00
Todd C. Miller
4416bd5977 Use libeventlog in sudoers instead of doing our own logging. 2020-10-26 16:10:40 -06:00
Todd C. Miller
541252beb1 Add default values in eventlog_setconf(). 2020-10-26 16:10:39 -06:00
Todd C. Miller
bd1ca79cca Add support for mailing eventlog entries and for logging raw messages.
These will be used by the sudoers plugin.
2020-10-26 16:10:37 -06:00
Todd C. Miller
fe6e0fb215 If no JSON callback is provided, store the contents of struct eventlog.
This moves the JSON formatting of struct eventlog out of libsudo_iolog
and into libsudo_eventlog where it belongs.
2020-10-26 15:43:43 -06:00
Todd C. Miller
4652698f8e struct eventlog contains submit_time, no need to pass it in directly. 2020-10-26 15:43:02 -06:00
Todd C. Miller
c0e91d7586 Add an errstr argument to eventlog_alert(). 2020-10-26 15:41:47 -06:00
Todd C. Miller
db72498257 Use struct eventlog in place of struct iolog_info. 2020-10-26 15:31:41 -06:00
Todd C. Miller
707437f6cb Refactor eventlog code into a library 2020-10-26 15:24:35 -06:00
Todd C. Miller
79921387a3 regen Makefiles 2020-10-20 19:23:46 -06:00
Todd C. Miller
88dcdcd11d Fix -Wshadow warnings. 2020-09-25 15:09:45 -06:00
Todd C. Miller
3d9154cd4f We need to link with NET_LIBS for gai_strerror() on some systems.
From Tim Rice
2020-09-05 21:10:28 -06:00
Todd C. Miller
0f8802676e Use config.h to handle systems without inline function support. 2020-09-05 19:18:49 -06:00
Todd C. Miller
d56347b981 Define sudo_warn_setlocale_t and use sudo_conv_t in sudo_fatal.h.
Works around a bug in older versions of the HP ANSI C compiler
and results in more readable code.
2020-09-05 08:21:43 -06:00
Todd C. Miller
c4b9f6136d Add missing #ifdef HAVE_CLOCK_GETTIME in getentropy_fallback()
From Tim Rice
2020-09-04 15:55:11 -06:00
Todd C. Miller
dad149f785 Add missing dependency info for cfmakeraw.lo in lib/util/Makefile.in
From Tim Rice
2020-09-04 15:51:45 -06:00
Todd C. Miller
0576eb0105 Replace "static inline" with "static __inline" for older compilers. 2020-09-04 13:52:46 -06:00