Todd C. Miller
e343e07543
Use #include <foo.h> instead of #include "foo.h" in most cases.
...
We rely on the include path to find many of these headers. It
especially doesn't make sense to use #include "foo.h" for headers
in the top-level include directory.
2023-09-25 10:13:28 -06:00
Todd C. Miller
d53bbb54b2
Add macros to determine the length of an integer type in string form.
...
Adapted from answer #6 in:
https://stackoverflow.com/questions/10536207/ansi-c-maximum-number-of-characters-printing-a-decimal-int
2023-09-19 15:15:02 -06:00
Todd C. Miller
db6baf2caf
Convert sudo_debug_enter and sudo_debug_exit into macros.
...
In most cases, these simply expand to a call to sudo_debug_printf2().
We need to keep the function versions around in libsudo_util for
backwards compatibility.
2023-07-10 14:30:38 -06:00
Todd C. Miller
2d12a41940
Fix sudo_debug_exit_uint_v1 declaration for fuzzers.
2023-07-10 11:27:28 -06:00
Todd C. Miller
eff4e1c0c5
Add missing sudo_debug_exit_uint_v1 stub for fuzzers.
2023-07-10 11:23:06 -06:00
Todd C. Miller
4f097eebd3
libsudo_util: make more bit flags unsigned.
2023-07-10 11:06:04 -06:00
Rose
5d758264ab
Give every printf-like function restrict qualifiers
...
The format value has to be a string literal, every time.
Otherwise, you are not using these functions correctly. To reinforce this fact, I putrestrict over every non-contrib example of this I could find.
2023-07-07 20:23:20 -04:00
Todd C. Miller
5768d374cc
libsudo_util: silence most -Wconversion warnings.
2023-07-07 15:07:04 -06:00
Todd C. Miller
2d1b3c369f
Change sudo_strtomode() to return mode_t.
2023-07-05 09:54:22 -06:00
Todd C. Miller
b926df1df2
Make the debug subsystem unsigned.
...
It was already unsigned in sudoers but not in the front-end or the
python plugin. Making this consistent resolves a lot of -Wconversion
warnings. Also clean up some other -Wconversion warnings in sudo_debug.c.
2023-07-01 16:14:50 -06:00
Rose
22079c3072
Avoid compiler casting warnings Part 2
...
This saves instructions that are related to casting as well as compiler warnings.
2023-06-29 13:10:27 -04:00
Todd C. Miller
cda03ed13f
Back out last change, len must be int, not size_t, for %.*s.
2023-05-03 13:36:07 -06:00
Rose
459a49b1fe
Prefer size_t over int, as casting can take extra instructions
2023-05-03 15:18:05 -04:00
Todd C. Miller
3421c8b6ce
Fix potential NULL pointer deference found by clang-analyzer.
2022-07-26 11:44:12 -06:00
Todd C. Miller
e5652fc65a
Linux execve(2) allows argv or envp to be NULL.
...
Add checks to make sure we don't deference a NULL pointer.
2022-07-14 09:29:40 -06:00
Todd C. Miller
13672f28df
Make sudo pass -Wwrite-strings
2022-06-28 16:33:15 -06:00
Todd C. Miller
55171df5e5
Check strftime(3) return value in all cases.
...
Old versions of strftime(3) didn't guarantee to NUL-terminate the buffer
so we explicitly clear the last byte of the buffer and check it.
2021-09-17 14:01:28 -06:00
Todd C. Miller
18f1884ddc
Use gmtime_r() and localtime_r() instead of gmtime() and localtime().
2021-09-17 10:55:06 -06:00
Todd C. Miller
46d71c4360
Store milliseconds in the debug file timestamp.
...
Sometime second granularity is not enough.
2021-09-17 10:55:06 -06:00
Todd C. Miller
dcab17900b
Add sudo_debug_register_v2() stub for fuzzing build.
2021-08-26 10:43:15 -06:00
Todd C. Miller
70aef0eb2d
sudo_debug_register: add minfd argument to specify lowest fd number
...
Use this in sudo_intercept.so to avoid allocating a low-numbered
fd which the shell reserves for use by scripts.
2021-08-26 09:57:24 -06:00
Todd C. Miller
79dbf9f17e
Disable debug code for FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
...
It will not be used and just confuses the coverage stats.
2021-02-28 19:52:03 -07:00
Todd C. Miller
4e11bc0e26
Suppress PVS Studio false positives.
2021-01-06 14:27: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
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
961a4afe67
Fix some warnings from pvs-studio
2020-08-12 13:45:09 -06:00
Todd C. Miller
8ef5c4cf9d
Set DEFAULT_TEXT_DOMAIN in lib/util's Makefile not individual .c files.
...
We no longer need to include sudo_gettext.h before sudo_compat.h
2020-05-18 11:19:58 -06:00
Todd C. Miller
446ae3f507
Include string.h unconditionally and only use strings.h for strn?casecmp()
...
In the pre-POSIX days BSD had strings.h, not string.h.
Now strings.h is only used for non-ANSI string functions.
2020-05-18 07:59:24 -06:00
Todd C. Miller
dd88460800
We no longer need to include headers we don't use for sudo*.h files.
...
Previously we needed to include headers required by the various
sudo*h files. Now those files are more self-sufficient and we
should only include headers needed by code in the various .c files.
2020-05-18 06:47:04 -06:00
Todd C. Miller
0e4c3c47d1
Move duplicated code to parse plugin debug flags to libsudo_util.
...
There's no need for four copies of sudo_debug_parse_flags().
2020-02-11 15:15:36 -07:00
Robert Manner
6710048c8d
lib/util/sudo_debug.c: add a function for querying if debugging is needed
...
for a level.
Rationale: this way we can avoid computing details for the log which will
not happen at all if the computation is slow.
2019-12-14 12:55:42 -07:00
Todd C. Miller
3ab29e29bb
Add reference counting to debug register/deregister.
...
Fixes a potential problem when an instance is re-registered.
2019-12-03 20:03:19 -07:00
Todd C. Miller
73dd3849c6
Better error message when debug log file cannot be opened.
2019-09-21 07:47:24 -06:00
Todd C. Miller
9d8f374397
Add ssizeof macro that returns ssize_t.
...
We can use this instead of casting the result of size_t to int.
Also change checks for snprintf() returning <=0 to <0.
2019-06-25 09:45:10 -06:00
Todd C. Miller
1e1ef61902
Add SPDX-License-Identifier to files.
2019-04-29 07:21:51 -06:00
Todd C. Miller
6c3d20cb41
Convert PVS-Studio comment to ANSI C.
2018-10-26 08:39:09 -06:00
Todd C. Miller
64e5d34c57
Add comments in .c files so PVS-Studio will check them.
2018-10-21 08:46:05 -06:00
Todd C. Miller
48fba3c2cc
update my email to Todd.Miller@sudo.ws
2017-12-03 17:53:40 -07:00
Todd C. Miller
e5dee1557e
Add NOTBEFORE and NOTAFTER command options similar to what is
...
already available in LDAP.
2017-02-18 15:35:48 -07:00
Todd C. Miller
334350af45
id_t is 64-bits on FreeBSD so use strtoll() there.
...
Fixes the strtoid regress.
2016-11-30 07:32:59 -07:00
Todd C. Miller
6c5936296f
Add SUDO_DEBUG_INSTANCE_ERROR return value for sudo_debug_register()
...
and check for it in places where we check the return value of
sudo_debug_register().
2016-11-21 06:37:23 -10:00
Todd C. Miller
3f022419ae
Be consistent with the naming of the variable used to store the
...
function return value. Previously, some code used "rval", some
used "ret". This standardizes on "ret" and uses "rc" for temporary
return codes.
2016-09-08 16:38:08 -06:00
Todd C. Miller
f683cbd582
Add definition of nitems for those without it and use it throughout.
2016-06-23 10:58:07 -06:00
Todd C. Miller
5016fa23df
When parsing debug entries, don't make a lower value override a
...
higher one. For example, for "pcomm@debug,all@warn" the "all@warn"
should not set pcomm to "warn" when it is already at "debug".
2016-01-21 07:43:25 -07:00
Todd C. Miller
8b12390abf
Add debug_return_ssize_t
2015-11-01 15:13:28 -07:00
Todd C. Miller
0b241088b3
There's no need to conditionalize the #include <unistd.h>, we require
...
a POSIX system.
2015-07-02 09:08:28 -06:00
Todd C. Miller
105f199f6b
Fix build on compilers w/o __func__ or __FUNCTION__
2015-06-30 10:41:14 -06:00
Todd C. Miller
d36e46cb6e
Must call round_nfds() with fd+1 since it takes a count not the fd
...
number. In other words, the lowest value is 1, not 0.
2015-06-23 13:49:56 -06:00
Todd C. Miller
4a07b472f0
Only include stddef.h where it is needed.
2015-06-20 05:34:35 -06:00
Todd C. Miller
dc883f2454
We require ANSI C so stop using the obsolete STDC_HEADERS.
2015-06-19 14:29:27 -06:00