Commit Graph

699 Commits

Author SHA1 Message Date
Todd C. Miller
81acb2bd7b Regenerate dependencies 2024-02-21 13:17:54 -07:00
Todd C. Miller
3944ab1fbe Use $(CPP) instead if $(CC) -E when buiding .i files from .c. 2024-02-21 12:31:50 -07:00
Todd C. Miller
9b073f3124 Using $< in a non-suffix rule context is a GNU make extension. 2024-02-21 13:01:14 -07:00
Yann E. MORIN
6ec958f27e lib/utils: detect failure to generate signals list and names
Currently, we generate the signal list and names by running cpp on our
header, and piping the result into sed.

However, when cpp fails [0], we do not catch that failure, as the error
code of the LHS of a pipe is lost, with the pipe returning the RHS-most
return code.

Fix that by introducing two new intermediate rules, each to generate the
preprocessed .i files, and use those as dependencies and input to the
rule that generates the headers. Those two .i files will be cleaned up
by the existing *.i glob.

[0] a failure happens on recent hosts, due to inconsistency with
time64_t and large-file support (lines elided and wrapped for
readability):

    /usr/bin/cpp [...] ./sys_signame.h \
    | /usr/bin/sed -e '1,/^int sudo_end_of_headers;/d' -e '/^#/d' > mksigname.h
    In file included from /usr/include/features.h:394,
                     from /usr/include/sys/types.h:25,
                     from ./sys_signame.h:4:
    /usr/include/features-time64.h:26:5: error: #error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
       26 | #   error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
          |     ^~~~~
    /usr/bin/gcc [...] ./mksigname.c -o mksigname
    In file included from /usr/include/features.h:394,
                     from /usr/include/bits/libc-header-start.h:33,
                     from /usr/include/stdlib.h:26,
                     from ./mksigname.c:27:
    /usr/include/features-time64.h:26:5: error: #error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
       26 | #   error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
          |     ^~~~~
    make[2]: *** [Makefile:263: mksigname] Error 1

In that case, we were lucky that the subsequent gcc call also failed,
and for the same reason. That time64_t and lfs issue should be fixed (at
least investigated), but that does not mean we should not be more robust
when parsing the header either.

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
2024-02-18 07:17:58 -07:00
Rose
725d3fdc20 Prefer putchar over fputc where possible
putchar is easier to understand than fputc and printf and does less work than those two do.
2024-01-13 15:24:43 -07:00
Todd C. Miller
00452471b1 Add check for sysconf(_SC_PAGESIZE) failure. 2024-01-01 11:03:01 -07:00
Todd C. Miller
1e03cbd0b4 sudo_term_is_raw: only try to lock the fd if it is a tty
This moves sudo_isatty() to libsudo_util so sudo_term_is_raw() can
use it.  Fixes GitHub issue #335
2023-12-09 12:54:56 -07:00
Todd C. Miller
24f443981f If sysconf(_SC_HOST_NAME_MAX) returns 0, just use 255.
This should not actually be possible.
2023-12-04 09:24:30 -07:00
THE-Spellchecker
5eba4b48cf Typographical and Grammatical fixes 2023-11-28 15:00:04 -07:00
Todd C. Miller
55db829087 No need to include sys/param.h here. 2023-11-26 09:28:40 -07:00
Todd C. Miller
be911b77dd Avoid using the u_int type, which is not portable. 2023-11-26 08:24:26 -07:00
Todd C. Miller
a6ac589cc1 sudo_term_restore: don't check c_cflag on systems with TCSASOFT.
If TCSASOFT is present, tcsetattr() will ignore c_cflag.
Fixes a bug where sudo_term_restore() would refuse to change
the terminal settings back if the PARENB control flag was set.
GitHub issue #326.
2023-11-08 16:58:02 -07:00
Todd C. Miller
097bec06bd sudo_conf_debug_files: special handling of DSO members for AIX
When matching debug files for AIX-style DSOs like sudoers.a(sudoers.so)
we want to match on the full name, the name without the member and
on the member itself.  This makes it possible to use the existing
examples in the sudo.conf fiile on AIX.
2023-11-03 11:29:20 -06:00
Todd C. Miller
78edde5ea1 Use NSIG instead of nitems(array) for the loop bound.
This matches the sudo_sys_siglist[] and sudo_sys_signame[] declarations.
2023-10-18 13:32:08 -06:00
Todd C. Miller
14d514e5ac Avoid using %zu or %zd with printf() and fprintf().
This prevents problems on systems where the system printf(3) is not
C99-compliant.  We use our own snprintf() on such systems so that
is safe.
2023-10-17 20:14:53 -06:00
Todd C. Miller
cf9fc5317e strlcpy_expand_host, sudo_getdelim, sudo_realpath: add restrict qualifier 2023-10-17 10:47:43 -06:00
Todd C. Miller
fabb6264fc Better handling of multiple sudo processes modifying terminal settings.
1. Lock the terminal before tcgetattr/tcsetattr
2. Don't restore terminal settings if changed by another process
3. Don't set terminal to raw mode if it is already raw
GitHub issue #312
2023-10-16 19:27:27 -06:00
Rose
e095069d2a Prefer fputs over fprintf where possible
fprintf does extra work and meant for formatting strings.
2023-10-15 10:28:57 -06:00
Rose
a4cbd7fe7b Swap calloc arguments to use them properly. 2023-10-15 10:19:58 -06:00
Rose
b2f8c5666d Use U, not UL, for 32-bit platforms
size_t is an unsigned int on 32-bit platforms, not an unsigned long.
2023-09-27 14:43:09 -06:00
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
49c7c1f4d3 Only cast TIOCSWINSZ to int on systems that might require it (AIX).
Otherwise we end up with a -Wconversion warning on systems where
the ioctl() request argument is unsigned long.
2023-09-15 10:26:29 -06:00
Todd C. Miller
034b2f3bdd Add testsudoers_setshellfile() and use it in testsudoers. 2023-09-10 16:38:53 -06:00
Todd C. Miller
166ef55aa7 Remove unnecessary sudo_gettext.h include and add missing const. 2023-09-10 10:23:04 -06:00
Todd C. Miller
df969d30b4 Silence a few remaining -Wconversion warnings. 2023-08-23 14:56:50 -06:00
Todd C. Miller
df730dec5d Suppress some other PVS-Studio false positives. 2023-08-21 13:21:49 -06:00
Todd C. Miller
811051d32a Use int, not short for events in the event API.
This fixes some -Wconversion warnings and fixes an inconsistency
between the libsudo_util event API and the plugin event API.  The
actual struct internals still use shorts to avoid changing the ABI.
2023-08-09 13:22:12 -06:00
Todd C. Miller
5f2a0a70e5 Fix printf format string mismatch now that 'i' is size_t. 2023-08-07 11:31:04 -06:00
Todd C. Miller
77f94f291a sudo_digest_getlen: return size_t, and 0 on error instead of -1
This is an API change, sudo_digest_getlen_v1 remains for binary
compatibility.
2023-08-07 08:43:13 -06:00
Todd C. Miller
7cb1f7f3a9 Cast TIOCSWINSZ to int to avoid overflow warning on 64-bit AIX. 2023-07-31 09:58:13 -06:00
Todd C. Miller
432ac12128 Pass TEST_VERBOSE to all test programs. 2023-07-20 10:13:40 -06:00
Todd C. Miller
4b5480cf76 Quiet a warning false positive with older versions of gcc. 2023-07-17 11:23:04 -06:00
Todd C. Miller
625653de08 sudo_term_raw: change the isig argument into a flags field
There are current two flags: SUDO_TERM_ISIG (enable terminal signals)
and SUDO_TERM_OFLAG (preserve output flags).
2023-07-14 13:12:51 -06:00
Todd C. Miller
a432aed4f0 realpath.c: include limits.h and use sysconf(_SC_SYMLOOP_MAX)
This is more portable and eliminates the need to check for SYMLOOP_MAX
(and provide it if missing) in configure.  Also quiet some -Wconversion
warnings.
2023-07-10 15:52:16 -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
bced0a7786 Make the remaining instances of digest_type unsigned. 2023-07-06 08:01:15 -06:00
Todd C. Miller
2d1b3c369f Change sudo_strtomode() to return mode_t. 2023-07-05 09:54:22 -06:00
Todd C. Miller
1f0f6b7c78 Fix some indentation. 2023-07-04 18:03:47 -06:00
Todd C. Miller
bfb6132d9c Add configure tests for __builtin_clz/__builtin_clzl 2023-07-04 12:39:31 -06:00
Todd C. Miller
0f69939d71 Add fallback for compilers without __builtin_clz/__builtin_clzl 2023-07-04 12:29:52 -06:00
Todd C. Miller
3a7ca0a834 sudo_pow2_roundup: fix 64-bit version when shifting 31 or more places
Shift 1UL instead of 1 to avoid overflowing an int.
2023-07-04 08:21:21 -06:00
Rose
8c3e4a33cd Optimize sudo_pow2_roundup_v1
No need to call sudo_pow2_roundup_v2.
2023-07-03 22:32:02 -04:00
Todd C. Miller
fa69ee5e1b Merge pull request #285 from AtariDreams/bug
Remove comment about algorithm being from bit-twiddling hacks
2023-07-03 20:26:20 -06:00
Rose
76d7aefb33 Remove comment about algorithm being from bit-twiddling hacks
Said comment no longer applies.
2023-07-03 22:24:55 -04:00