]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
4 months agolib/: Saturate addition to avoid overflow
Tobias Stoeckmann [Mon, 18 Dec 2023 19:45:44 +0000 (20:45 +0100)] 
lib/: Saturate addition to avoid overflow

Very large values in /etc/shadow could lead to overflows.  Make sure
that these calculations are saturated at LONG_MAX.  Since entries are
based on days and not seconds since epoch, saturating won't hurt anyone.

Co-developed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/chage.c: Unify long overflow checks in print_day_as_date()
Tobias Stoeckmann [Thu, 14 Dec 2023 11:33:35 +0000 (12:33 +0100)] 
src/chage.c: Unify long overflow checks in print_day_as_date()

The conversion from day to seconds can be done in print_date
(renamed to print_day_as_date for clarification).  This has the nice
benefit that DAY multiplication and long to time_t conversion are done
at just one place.

Co-developed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agoetc/pam.d/Makefile.am: Fix typo
Alejandro Colomar [Tue, 13 Feb 2024 12:17:44 +0000 (13:17 +0100)] 
etc/pam.d/Makefile.am: Fix typo

The commit we're fixing mentions that it wanted to move 'chpasswd', but
it removed 'ch_g_passwd' from 'pamd_acct_tools_files' and added
'chpasswd' to 'pamd_files'.  It seems it removed the wrong thing by
accident.

Fixes: 341d80c2c751 ("Makefile: move chpasswd and newusers to pamd target")
Link: <https://github.com/shadow-maint/shadow/pull/928#discussion_r1487687347>
Link: <https://github.com/shadow-maint/shadow/issues/926#issuecomment-1941324761>
Reported-by: Dominique Leuenberger <dleuenberger@suse.com>
Reported-by: Michael Vetter <jubalh@iodoru.org>
Cc: David Runge <dvzrv@archlinux.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Tested-by: Michael Vetter <jubalh@iodoru.org>
Reviewed-by: Michael Vetter <jubalh@iodoru.org>
Reviewed-by: loqs <https://github.com/loqs>
Co-developed-by: Dominique Leuenberger <dleuenberger@suse.com>
Signed-off-by: Dominique Leuenberger <dleuenberger@suse.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agoAUTHORS.md: Format list
Alejandro Colomar [Tue, 6 Feb 2024 09:44:36 +0000 (10:44 +0100)] 
AUTHORS.md: Format list

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/chkname.c: Use precise comment
Tobias Stoeckmann [Sat, 3 Feb 2024 00:12:16 +0000 (01:12 +0100)] 
lib/chkname.c: Use precise comment

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 months agolib/chkname.c: Support unlimited user name lengths
Tobias Stoeckmann [Sat, 3 Feb 2024 00:10:22 +0000 (01:10 +0100)] 
lib/chkname.c: Support unlimited user name lengths

If the system does not have a user name length limit, support it
accordingly. If the system has no _SC_LOGIN_NAME_MAX, use
LOGIN_NAME_MAX constant instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 months agolib/chkname.c: Take NUL byte into account
Tobias Stoeckmann [Sat, 3 Feb 2024 00:07:58 +0000 (01:07 +0100)] 
lib/chkname.c: Take NUL byte into account

The _SC_LOGIN_NAME_MAX value includes space for the NUL byte. The length
of name must smaller than this value to be valid.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 months agorelease 4.15.0-rc1 4.15.0-rc1
Serge Hallyn [Thu, 1 Feb 2024 23:02:48 +0000 (17:02 -0600)] 
release 4.15.0-rc1

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 months agosrc/sulogin.c: Remove unused variable
Samanta Navarro [Fri, 19 Jan 2024 11:55:24 +0000 (11:55 +0000)] 
src/sulogin.c: Remove unused variable

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 months agosrc/sulogin.c: Simplify password handling
Samanta Navarro [Fri, 19 Jan 2024 11:54:14 +0000 (11:54 +0000)] 
src/sulogin.c: Simplify password handling

The password returned by agetpass can be used directly without copying
it into a char array first.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 months agosrc/sulogin.c: Use a do-while loop
Samanta Navarro [Fri, 19 Jan 2024 11:53:53 +0000 (11:53 +0000)] 
src/sulogin.c: Use a do-while loop

Clarify how this endless while(true) loop can be stopped by using a
boolean variable as condition and turn it into a do-while loop.

Suggested-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 months agotests/unit/test_atoi_strtoi.c: Test strtou_noneg()
Alejandro Colomar [Sat, 6 Jan 2024 19:35:29 +0000 (20:35 +0100)] 
tests/unit/test_atoi_strtoi.c: Test strtou_noneg()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/atoi/strtou_noneg.[ch]: Add strtou_noneg()
Alejandro Colomar [Sat, 6 Jan 2024 18:46:20 +0000 (19:46 +0100)] 
lib/atoi/strtou_noneg.[ch]: Add strtou_noneg()

It's like strtou_(), but rejects negative input, instead of silently
converting it to unsigned.

Link: <https://softwareengineering.stackexchange.com/a/449060/332848>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agotests/unit/Makefile.am: tfix
Alejandro Colomar [Sun, 7 Jan 2024 01:35:00 +0000 (02:35 +0100)] 
tests/unit/Makefile.am: tfix

Fix typo.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agotests/unit/test_atoi_strtoi.c: Test strtoi_()
Alejandro Colomar [Sat, 6 Jan 2024 18:06:27 +0000 (19:06 +0100)] 
tests/unit/test_atoi_strtoi.c: Test strtoi_()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/atoi/strtoi.[ch]: strtoi_(), strtou_(): Add functions
Alejandro Colomar [Fri, 1 Dec 2023 21:34:31 +0000 (22:34 +0100)] 
lib/atoi/strtoi.[ch]: strtoi_(), strtou_(): Add functions

These functions are identical to strtoi(3bsd) and strtou(3bsd), except
for one important thing: if both ERANGE and ENOTSUP conditions happen,
the BSD functions report ENOTSUP, which is bogus; our strtoi_() and
strtou_() report ERANGE.

Link: <https://lists.sr.ht/~hallyn/shadow/%3CZZoQDms6Sv6e5SPE%40debian%3E>
Link: <https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57828>
Cc: Thorsten Glaser <tg@mirbsd.de>
Cc: christos <christos@netbsd.org>
Cc: roy <roy@netbsd.org>
Cc: Guillem Jover <guillem@hadrons.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/passwd.c: implement reading password from pipe
Tomas Halman [Thu, 25 Jan 2024 10:00:09 +0000 (11:00 +0100)] 
src/passwd.c: implement reading password from pipe

New option --stdin/-t is available for root user. It is useful
for automation/setup and it makes shadow utils passwd more versatile.

Signed-off-by: Tomas Halman <tomas@halman.net>
4 months agolib/agetpass.[ch]: add function ro read from pipe
Tomas Halman [Thu, 25 Jan 2024 09:56:10 +0000 (10:56 +0100)] 
lib/agetpass.[ch]: add function ro read from pipe

Add alternative function to agetpass for reading password
from stdin or pipe.

Signed-off-by: Tomas Halman <tomas@halman.net>
4 months agoMakefile: move chpasswd and newusers to pamd target
loqs [Fri, 26 Jan 2024 12:41:09 +0000 (12:41 +0000)] 
Makefile: move chpasswd and newusers to pamd target

Install pam configs for chpasswd and newusers when using ./configure --with-libpam --disable-account-tools-setuid.
Fixes https://github.com/shadow-maint/shadow/issues/810.

Tested-by: David Runge <dvzrv@archlinux.org>
4 months agolib/, src/: Make the use of MAYBE_UNUSED macro consistent
Pablo Saavedra [Tue, 23 Jan 2024 07:33:37 +0000 (08:33 +0100)] 
lib/, src/: Make the use of MAYBE_UNUSED macro consistent

There is an inconsistent use of the MAYBE_UNUSED macro. Sometimes the
`int unused(x)` form is used form and others the `unused int x`. We'd
like to use the second form always.

Related-To: https://github.com/shadow-maint/shadow/issues/918
Suggested-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
4 months agolib/, src/: Rename 'unused' macro as 'MAYBE_UNUSED'
Pablo Saavedra [Mon, 22 Jan 2024 09:00:54 +0000 (10:00 +0100)] 
lib/, src/: Rename 'unused' macro as 'MAYBE_UNUSED'

Related-To: https://github.com/shadow-maint/shadow/issues/918
Suggested-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
4 months agoFix Build error 'parameter name omitted' in logind
Pablo Saavedra [Mon, 22 Jan 2024 13:46:15 +0000 (14:46 +0100)] 
Fix Build error 'parameter name omitted' in logind

Fixes #918 by adding the omitted parameter name in
active_sessions_count().

Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
4 months agosrc/sulogin.c: pw_entry(): Report errors by returning -1
Alejandro Colomar [Mon, 29 Jan 2024 15:28:02 +0000 (16:28 +0100)] 
src/sulogin.c: pw_entry(): Report errors by returning -1

Cc: Samanta Navarro <ferivoz@riseup.net>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/passwd.c: Remove comments about flags that don't exist
Alejandro Colomar [Mon, 29 Jan 2024 11:59:14 +0000 (12:59 +0100)] 
src/passwd.c: Remove comments about flags that don't exist

Those flags have never existed, AFAICS.

Closes: <https://github.com/shadow-maint/shadow/issues/929>
Cc: Tomas Halman <tomas@halman.net>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agoLink correctly with libdl
Sam James [Sun, 21 Jan 2024 14:58:33 +0000 (14:58 +0000)] 
Link correctly with libdl

This fixes build with glibc-2.33 (newer glibc merged libdl and libpthread
into libc):
```
libtool: link: x86_64-pc-linux-gnu-gcc -isystem /usr/include/bsd -DLIBBSD_OVERLAY -O2 -pipe -Wl,-O1 -o login login.o login_nopam.o  -Wl,--as-needed ../lib/.libs/libshadow.a -lcrypt -lsystemd -lpam -lpam_misc -lbsd
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: ../lib/.libs/libshadow.a(libshadow_la-nss.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /lib64/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
```

In Debian, the needed macro from libtool seems to be in libltdl-dev.

Signed-off-by: Sam James <sam@gentoo.org>
4 months agoautogen.sh: CFLAGS: Use -Wno-unknown-attributes; Clang doesn't know [[gnu::access()]]
Alejandro Colomar [Mon, 22 Jan 2024 23:10:14 +0000 (00:10 +0100)] 
autogen.sh: CFLAGS: Use -Wno-unknown-attributes; Clang doesn't know [[gnu::access()]]

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agoautogen.sh: CFLAGS: Add some -Werror=... flags that will be default soon
Alejandro Colomar [Mon, 22 Jan 2024 21:25:34 +0000 (22:25 +0100)] 
autogen.sh: CFLAGS: Add some -Werror=... flags that will be default soon

Clang 16 and GCC 14 have upgraded several warnings to errors by default.
Also, there are new warnings that will be requirements of ISO C23.  Add
all of those to our build.

Use Clang's -Wno-unknown-attribute-option, to ignore warnings that are
exclusive of GCC.  Sadly, GCC doesn't have such an option.

Link: <https://wiki.gentoo.org/wiki/Modern_C_porting#What_changed.3F>
Link: <https://github.com/shadow-maint/shadow/issues/922>
Suggested-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/usermod.c: grp_update(): Remove scope of variable, and fix const correctness
Alejandro Colomar [Mon, 22 Jan 2024 22:52:09 +0000 (23:52 +0100)] 
src/usermod.c: grp_update(): Remove scope of variable, and fix const correctness

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/useradd.c: get_defaults(): Use const temporary pointer to fix const correctness
Alejandro Colomar [Mon, 22 Jan 2024 22:49:19 +0000 (23:49 +0100)] 
src/useradd.c: get_defaults(): Use const temporary pointer to fix const correctness

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/su.c: Use const_cast() to silence -Wincompatible-pointer-types-discards-qualifiers
Alejandro Colomar [Mon, 22 Jan 2024 21:52:59 +0000 (22:52 +0100)] 
src/su.c: Use const_cast() to silence -Wincompatible-pointer-types-discards-qualifiers

argv is passed to execve(3), which for historic reasons is non-const,
but doesn't modify the strings.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/cast.h: const_cast(): Add macro for dropping 'const'
Alejandro Colomar [Sun, 7 Jan 2024 00:00:45 +0000 (01:00 +0100)] 
lib/cast.h: const_cast(): Add macro for dropping 'const'

Uses of this macro indicate a code smell, but in some cases, libc
functions require breaking const correctness.  Use this macro to wrap
casts in such cases, so that we limit the danger of the cast.

It only permits discarding const.  Discarding any other qualifiers, or
doing other type changes should result in a compile-time error.

Link: <https://software.codidact.com/posts/286575/287345#answer-287345>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/must_be.h: is_same_type(): Add macro
Alejandro Colomar [Mon, 22 Jan 2024 21:43:40 +0000 (22:43 +0100)] 
lib/must_be.h: is_same_type(): Add macro

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/must_be.h: is_same_typeof(): Rename macro
Alejandro Colomar [Mon, 22 Jan 2024 21:42:46 +0000 (22:42 +0100)] 
lib/must_be.h: is_same_typeof(): Rename macro

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/su.c: do_check_perms(): Fix -Wincompatible-pointer-types bug
Alejandro Colomar [Sun, 21 Jan 2024 12:48:21 +0000 (13:48 +0100)] 
src/su.c: do_check_perms(): Fix -Wincompatible-pointer-types bug

Fixes: ef95bb7ed139 ("src/su.c: Fix type of variable")
Closes: <https://github.com/shadow-maint/shadow/issues/915>
Reported-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agotests/unit/test_atoi_strtou_noneg.c: Test strtou[l]l_noneg()
Alejandro Colomar [Sat, 6 Jan 2024 17:00:19 +0000 (18:00 +0100)] 
tests/unit/test_atoi_strtou_noneg.c: Test strtou[l]l_noneg()

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/, src/: Replace strtou[l]l(3) by strtou[l]l_noneg()
Alejandro Colomar [Mon, 11 Dec 2023 00:06:05 +0000 (01:06 +0100)] 
lib/, src/: Replace strtou[l]l(3) by strtou[l]l_noneg()

strtou[l]l(3) silently converts negative numbers into positive.  This
behavior is wrong: a negative value should be parsed as a negative
value, which would underflow unsigned (long) long, and so would return
the smallest possible value, 0, and set errno to ERANGE to report an
error.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/atoi/strtou_noneg.[ch]: Add strtou[l]l_noneg()
Alejandro Colomar [Sun, 10 Dec 2023 23:51:05 +0000 (00:51 +0100)] 
lib/atoi/strtou_noneg.[ch]: Add strtou[l]l_noneg()

These functions reject negative numbers, instead of silently converting
them into unsigned, which strtou[l]l(3) do.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/sulogin.c: Free previously allocated memory
Samanta Navarro [Thu, 18 Jan 2024 11:53:41 +0000 (11:53 +0000)] 
src/sulogin.c: Free previously allocated memory

The sulogin program calls pw_entry in a loop while incorrect root
passwords are entered.

Free the previously allocated memory to avoid memory exhaustion.

Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
5 months agosrc/sulogin.c: Remove 'static' from local variable, but keep initialization
Alejandro Colomar [Wed, 17 Jan 2024 16:08:50 +0000 (17:08 +0100)] 
src/sulogin.c: Remove 'static' from local variable, but keep initialization

We don't need 'static', because it's in main(), which is only called
once.  However, we will need initialization as if it were 'static', so
use ={} to initialize it.  This will allow freeing the pointers before
they have been allocated.

Cc: Samanta Navarro <ferivoz@riseup.net>
Suggested-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/sulogin.c: Remove 'static' from a temporary variable
Alejandro Colomar [Wed, 17 Jan 2024 16:02:27 +0000 (17:02 +0100)] 
src/sulogin.c: Remove 'static' from a temporary variable

There's no need to keep 'pass' in .bss:

$ grep -nC3 '\<pass\>' src/sulogin.c
58-/*ARGSUSED*/ int main (int argc, char **argv)
59-{
60- int     err = 0;
61: char    pass[BUFSIZ];
62- char    **envp = environ;
63- TERMIO  termio;
64-#ifndef USE_PAM
--
166-#endif
167- exit (0);
168- }
169: STRTCPY(pass, cp);
170- erase_pass (cp);
171-
172: if (valid (pass, &pwent)) { /* check encrypted passwords ... */
173- break; /* ... encrypted passwords matched */
174- }
175-
176- sleep (2);
177- (void) puts (_("Login incorrect"));
178- }
179: MEMZERO(pass);
180- (void) alarm (0);
181- (void) signal (SIGALRM, SIG_DFL);
182- environ = newenvp; /* make new environment active */

Cc: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/sulogin.c: Align local variables
Alejandro Colomar [Wed, 17 Jan 2024 16:00:48 +0000 (17:00 +0100)] 
src/sulogin.c: Align local variables

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/sulogin.c: Make static variables local to main()
Alejandro Colomar [Wed, 17 Jan 2024 15:57:02 +0000 (16:57 +0100)] 
src/sulogin.c: Make static variables local to main()

Those variables are only used in main().  Restrict their scope.
Keep them static (.bss), as changing that may be dangerous.

Suggested-by: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/sulogin.c: pw_entry(): Don't else after return
Alejandro Colomar [Wed, 17 Jan 2024 15:52:12 +0000 (16:52 +0100)] 
src/sulogin.c: pw_entry(): Don't else after return

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/, po/: pw_entry(): Move function to src/sulogin.c
Alejandro Colomar [Wed, 17 Jan 2024 15:48:53 +0000 (16:48 +0100)] 
lib/, src/, po/: pw_entry(): Move function to src/sulogin.c

That's the only file where it's called, and it's a delicate function.
Reduce the chances that other files call it.

Link: <https://github.com/shadow-maint/shadow/pull/908>
Suggested-by: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, tests/: addsl(): Add addsl(), a variadic macro
Alejandro Colomar [Sat, 6 Jan 2024 01:17:38 +0000 (02:17 +0100)] 
lib/, tests/: addsl(): Add addsl(), a variadic macro

Add a variadic macro addsl() that accepts an arbitrary number of
addends, instead of having specific versions like addsl2() or addsl3().

It is internally implemented by the addslN() function, which itself
calls addsl2().  addsl3() is now obsolete and thus removed.

Code should just call addsl().

Link: <https://github.com/shadow-maint/shadow/pull/882#discussion_r1437155212>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, tests/: addsl2(): Rename addsl() to addsl2()
Alejandro Colomar [Sat, 6 Jan 2024 01:25:21 +0000 (02:25 +0100)] 
lib/, tests/: addsl2(): Rename addsl() to addsl2()

This is for consistency with addsl3(), and in preparation for the
following commit, which will unify the interface into a single addsl()
macro.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/defines.h: Don't wrap #undef in #ifdef
Alejandro Colomar [Fri, 12 Jan 2024 00:58:28 +0000 (01:58 +0100)] 
lib/defines.h: Don't wrap #undef in #ifdef

ISO C guarantees that #undef is a no-op if there is no such macro.

C11::6.10.3.5p2:
> A preprocessing directive of the form
>
>       # undef identifier new-line
>
> causes the specified identifier no longer to be defined as a macro
> name.  It is ignored if the specified identifier is not currently
> defined as a macro name.

Link: <http://port70.net/~nsz/c/c11/n1570.html#6.10.3.5p2>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/idmapping.c: write_mapping(): Fixx off-by-one bug
Alejandro Colomar [Thu, 11 Jan 2024 18:12:24 +0000 (19:12 +0100)] 
lib/idmapping.c: write_mapping(): Fixx off-by-one bug

Link: <https://github.com/shadow-maint/shadow/commit/673c2a6f9aa6c69588f4c1be08589b8d3475a520#r136830993>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/: Use 'restrict' alongside [[gnu::access()]]
Alejandro Colomar [Sat, 6 Jan 2024 12:41:16 +0000 (13:41 +0100)] 
lib/: Use 'restrict' alongside [[gnu::access()]]

const + restrict imply read_only.

Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/: Use ATTR_ACCESS() instead of /*@out@*/
Alejandro Colomar [Mon, 11 Dec 2023 13:21:24 +0000 (14:21 +0100)] 
lib/: Use ATTR_ACCESS() instead of /*@out@*/

The compiler seems to ignore the attribute in a function pointer,
though.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/: get[u]long(): Use ATTR_ACCESS() instead of /*@out@*/
Alejandro Colomar [Mon, 11 Dec 2023 13:16:31 +0000 (14:16 +0100)] 
lib/: get[u]long(): Use ATTR_ACCESS() instead of /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/: Remove incorrect /*@out@*/ comment from functions that read the pointee
Alejandro Colomar [Mon, 11 Dec 2023 13:01:38 +0000 (14:01 +0100)] 
lib/: Remove incorrect /*@out@*/ comment from functions that read the pointee

These functions (e.g., gr_free()), explicitly dereference the pointer
and read the pointee.

The /@out@/ comment, which is (almost) analogous to the
[[gnu::access(write_only, ...)]] attribute, means that the pointee can
be uninitialized, since it won't read it.  There's a difference between
/@out@/ and the GCC attribute: the attribute doesn't require that the
call writes to the pointee, while /@out@/ requires that the pointee be
fully initialized after the call, so it _must_ write to it.

A guess of why it was used is that these functions are similar to
free(3), which does not read the memory it frees, and so one would
assume that if it doesn't read, write_only (or equivalents) are good.
That's wrong in several ways:

-  free(3) does not read _nor_ write to the memory, so it would
   be slightly inappropriate to use write_only with it.  It wouldn't be
   "wrong", but [[gnu::access(none, ...)]] would be more appropriate.

-  Because /@out@/ requires that the call writes to the pointee, it
   would be wrong to use it in free(3), which doesn't write to the
   pointee.

-  Our functions are similar to free(3) conceptually, but they don't
   behave like free(3), since they do read the memory (pointee) (and
   also write to it), and thus they're actually read_write.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/: Remove /*@out@*/ comments in return type
Alejandro Colomar [Mon, 11 Dec 2023 12:48:35 +0000 (13:48 +0100)] 
lib/: Remove /*@out@*/ comments in return type

/*@out@*/ makes no sense in the return of a function, AFAICS.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/: fgetsx(): Use ATTR_ACCESS() instead of /*@out@*/
Alejandro Colomar [Mon, 11 Dec 2023 13:10:38 +0000 (14:10 +0100)] 
lib/: fgetsx(): Use ATTR_ACCESS() instead of /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/: run_command(): Use ATTR_ACCESS() instead of /*@out@*/
Alejandro Colomar [Mon, 11 Dec 2023 12:36:53 +0000 (13:36 +0100)] 
lib/: run_command(): Use ATTR_ACCESS() instead of /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/attr.h: Add ATTR_ACCESS()
Alejandro Colomar [Mon, 11 Dec 2023 12:32:12 +0000 (13:32 +0100)] 
lib/attr.h: Add ATTR_ACCESS()

This will replace the existing comments like /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/sgetgrent.c: fix null pointer dereference
Samanta Navarro [Fri, 12 Jan 2024 11:49:27 +0000 (11:49 +0000)] 
lib/sgetgrent.c: fix null pointer dereference

If reallocation fails in function list, then reset the size to 0 again.
Without the reset, the next call assumes that `members` points to
a memory location with reserved space.

Also use size_t instead of int for size to prevent signed integer
overflows. The length of group lines is not limited.

Fixes 45c0003e53ab671c63dcd530fd9f3245d3b29e76 (4.14 release series)

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
5 months agolib/: get_pid(): Use the usual -1 as an error code
Alejandro Colomar [Sat, 2 Dec 2023 00:21:01 +0000 (01:21 +0100)] 
lib/: get_pid(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: get_uid(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 23:27:04 +0000 (00:27 +0100)] 
lib/, src/: get_uid(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: get_gid(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 23:23:06 +0000 (00:23 +0100)] 
lib/, src/: get_gid(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: getrange(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 22:10:06 +0000 (23:10 +0100)] 
lib/, src/: getrange(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/getrange.c: Reduce indentation
Alejandro Colomar [Sat, 30 Dec 2023 13:08:13 +0000 (14:08 +0100)] 
lib/getrange.c: Reduce indentation

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: getulong(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 19:33:20 +0000 (20:33 +0100)] 
lib/, src/: getulong(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: getlong(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 19:23:48 +0000 (20:23 +0100)] 
lib/, src/: getlong(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agotests/unit/test_adds.c: Test addsl() and addsl3()
Alejandro Colomar [Wed, 20 Dec 2023 21:09:36 +0000 (22:09 +0100)] 
tests/unit/test_adds.c: Test addsl() and addsl3()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/adds.[ch]: Add addsl() and addsl3()
Alejandro Colomar [Wed, 20 Dec 2023 20:43:03 +0000 (21:43 +0100)] 
lib/adds.[ch]: Add addsl() and addsl3()

These functions add 2 or 3 longs, saturating to LONG_{MIN,MAX} instead
of overflowing.

Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/: Fix long/time_t handling
Tobias Stoeckmann [Thu, 14 Dec 2023 11:11:28 +0000 (12:11 +0100)] 
src/: Fix long/time_t handling

Special care has to be taken for 32 bit systems with a 64 bit time_t,
since their long data type is still 32 bit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/passwd.c: Add overflow check
Tobias Stoeckmann [Wed, 20 Dec 2023 19:48:54 +0000 (20:48 +0100)] 
src/passwd.c: Add overflow check

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/passwd.c: Switch to day precision
Tobias Stoeckmann [Thu, 14 Dec 2023 10:54:00 +0000 (11:54 +0100)] 
src/passwd.c: Switch to day precision

The size of time_t varies across systems, but since data type long is
more than enough to calculate with days (precision of shadow file),
use it instead.

Just in case a shadow file contains huge values, check for a possible
signed integer overflow.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: Remove SCALE definition
Tobias Stoeckmann [Wed, 13 Dec 2023 20:25:51 +0000 (20:25 +0000)] 
lib/, src/: Remove SCALE definition

SCALE is always DAY (and has to be always DAY), so replace it with DAY
in source code and remove unneeded calculations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agoman/: add BCRYPT and YESCRYPT information
Tobias Stoeckmann [Tue, 19 Dec 2023 16:39:54 +0000 (17:39 +0100)] 
man/: add BCRYPT and YESCRYPT information

The BCRYPT and YESCRYPT relevant items should be described in
manual pages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 months agoman/: CONSOLE_GROUPS is only used without PAM
Tobias Stoeckmann [Wed, 20 Dec 2023 17:55:09 +0000 (18:55 +0100)] 
man/: CONSOLE_GROUPS is only used without PAM

CONSOLE_GROUPS is only used if PAM is not in use, just like
CONSOLE itself.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 months agoman/: ENV_HZ is only used without PAM
Tobias Stoeckmann [Wed, 20 Dec 2023 11:27:24 +0000 (12:27 +0100)] 
man/: ENV_HZ is only used without PAM

Contrary to the comment in ENV_HZ.xml, ENV_HZ is not even used in
sulogin (anymore) if PAM support is enabled.

Skip paragraphs of sulogin if PAM support is enabled, since they would
be empty now.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 months agolib/defines.h: Use 'time_t' for DAY
Alejandro Colomar [Wed, 20 Dec 2023 16:56:32 +0000 (17:56 +0100)] 
lib/defines.h: Use 'time_t' for DAY

Special care has to be taken for 32 bit systems with a 64 bit time_t,
since their long data type is still 32 bit.

Since this macro expresses a number of seconds, and seconds are in units
of 'time_t' in C, the appropriate type for the multiplication is
'time_t'.

Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agologin.defs.5: Be specific that only -1 is allowed
Tobias Stoeckmann [Wed, 20 Dec 2023 20:11:11 +0000 (21:11 +0100)] 
login.defs.5: Be specific that only -1 is allowed

Other negative values can have bad effects and won't be allowed
anymore.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 months agolib/getdef.c: Reject negative values in getdef_* except -1
Tobias Stoeckmann [Tue, 19 Dec 2023 12:06:02 +0000 (13:06 +0100)] 
lib/getdef.c: Reject negative values in getdef_* except -1

The values are retrieved from login.defs files, which normally do not
contain negative values. In fact, negative value -1 is used in many
code places as "feature disabled", which is normally achieved by
simply commenting out the key from the file.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 months agoman/: Support compiling in build directory
Tobias Stoeckmann [Tue, 19 Dec 2023 18:24:18 +0000 (19:24 +0100)] 
man/: Support compiling in build directory

Having a dedicated build directory breaks manual page creation.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agotests/unit/test_sprintf.c: Test SNPRINTF()
Alejandro Colomar [Wed, 22 Nov 2023 18:39:02 +0000 (19:39 +0100)] 
tests/unit/test_sprintf.c: Test SNPRINTF()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/, src/: Use SNPRINTF() instead of its pattern
Alejandro Colomar [Sat, 26 Aug 2023 10:32:32 +0000 (12:32 +0200)] 
lib/, src/: Use SNPRINTF() instead of its pattern

The variable declarations for the buffers have been aligned in this
commit, so that they appear in the diff, making it easier to review.

Some important but somewhat tangent changes included in this commit:

-  lib/nss.c: The size was being defined as 65, but then used as 64.
   That was a bug, although not an important one; we were just wasting
   one byte.  Fix that while we replace snprintf() by SNPRINTF(), which
   will get the size from sizeof(), and thus will use the real size.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/string/sprintf.[ch]: Add [v]snprintf_()
Alejandro Colomar [Sat, 26 Aug 2023 12:54:44 +0000 (14:54 +0200)] 
lib/string/sprintf.[ch]: Add [v]snprintf_()

These functions are like [v]snprintf(3), but return -1 on truncation,
which makes it easier to test.  In fact, the API of swprintf(3), which
was invented later than snprintf(3), and is the wide-character version
of it, is identical to this snprintf_().

snprintf(3) is iseful in two cases:

-  We don't care if the output is truncated.  snprintf(3) is fine for
   those, and the return value can be ignored.  But snprintf_() is also
   fine for those.

-  Truncation is bad.  In that case, it's as bad as a hard error (-1)
   from snprintf, so merging both problems into the same error code
   makes it easier to handle errors.  Return the length if no truncation
   so that we can use it if necessary.

Not returning the whole length before truncation makes a better API,
which need not read the entire input, so it's less vulnerable to DoS
attacks when a malicious user controls the input.

Use these functions to implement SNPRINTF().

Cc: Samanta Navarro <ferivoz@riseup.net>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/string/sprintf.h: Add SNPRINTF() macro
Alejandro Colomar [Sat, 26 Aug 2023 10:11:59 +0000 (12:11 +0200)] 
lib/string/sprintf.h: Add SNPRINTF() macro

It wraps snprintf(3) so that it performs some steps that one might
forget, or might be prone to accidents:

-  It calculates the size of the destination buffer, and makes sure it's
   an array (otherwise, using sizeof(s) would be very bad).

-  It calculates if there's truncation or an error, returning -1 if so.

BTW, this macro doesn't have any issues of double evaluation, because
sizeof() doesn't evaluate its argument (unless it's a VLA, but then the
static_assert(3) within NITEMS() makes sure VLAs are not allowed).

This macro is very similar to STRTCPY(), defined in
<lib/string/strtcpy.h>.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agosrc/chfn,chpasswd,newusers: declare fatal_exit() NORETURN
Christian Göttsche [Mon, 11 Dec 2023 17:12:24 +0000 (18:12 +0100)] 
src/chfn,chpasswd,newusers: declare fatal_exit() NORETURN

Help static analyzers to understand fatal_exit() does never return.

6 months agolib: avoid format truncation
Christian Göttsche [Mon, 11 Dec 2023 16:53:28 +0000 (17:53 +0100)] 
lib: avoid format truncation

    commonio.c: In function 'commonio_unlock':
    commonio.c:487:49: warning: '.lock' directive output may be truncated writing 5 bytes into a region of size between 1 and 1024 [-Wformat-truncation=]
      487 |                 snprintf (lock, sizeof lock, "%s.lock", db->filename);
          |                                                 ^~~~~
    commonio.c:487:17: note: 'snprintf' output between 6 and 1029 bytes into a destination of size 1024
      487 |                 snprintf (lock, sizeof lock, "%s.lock", db->filename);
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

6 months agolib: avoid double close on error
Christian Göttsche [Mon, 11 Dec 2023 16:45:26 +0000 (17:45 +0100)] 
lib: avoid double close on error

    log.c:90:24: warning: double 'close' of file descriptor 'fd' [CWE-1341] [-Wanalyzer-fd-double-close]
    failure.c:94:24: warning: double 'close' of file descriptor 'fd' [CWE-1341] [-Wanalyzer-fd-double-close]
    failure.c:193:32: warning: double 'close' of file descriptor 'fd' [CWE-1341] [-Wanalyzer-fd-double-close]
    utmp.c:103:24: warning: double 'close' of file descriptor 'fd' [CWE-1341] [-Wanalyzer-fd-double-close]

6 months agoUpdate close(2) checking
Christian Göttsche [Mon, 11 Dec 2023 16:32:13 +0000 (17:32 +0100)] 
Update close(2) checking

Check for close(2) failure at more places closing a file descriptor
written to.

Also ignore failures with errno set to EINTR (see man:close(2) for
details).

6 months agosrc/useradd: free string
Christian Göttsche [Mon, 11 Dec 2023 16:27:44 +0000 (17:27 +0100)] 
src/useradd: free string

    useradd.c:2329:10: warning: Potential leak of memory pointed to by 'btrfs_check' [unix.Malloc]

6 months agolib/failure,utmp: update error messages
Christian Göttsche [Mon, 11 Dec 2023 16:21:25 +0000 (17:21 +0100)] 
lib/failure,utmp: update error messages

Include errno description.

6 months agolib/utmp: merge file access
Christian Göttsche [Mon, 11 Dec 2023 16:18:38 +0000 (17:18 +0100)] 
lib/utmp: merge file access

Avoid checking if the file exists before opening it.

Resolves a CodeQL report of Time-of-check time-of-use filesystem race
condition.

6 months agosrc/useradd: avoid usage of sprintf
Christian Göttsche [Mon, 11 Dec 2023 16:13:43 +0000 (17:13 +0100)] 
src/useradd: avoid usage of sprintf

sprintf(3) does not take the destination buffer into account. Although
the destination in these case is large enough, sprintf(3) indicates a
code smell.

Use the xasprintf() wrapper.

6 months agosrc/usermod,groups: use checked malloc
Christian Göttsche [Mon, 11 Dec 2023 16:09:06 +0000 (17:09 +0100)] 
src/usermod,groups: use checked malloc

    usermod.c:2165:24: warning: dereference of possibly-NULL ‘user_groups’ [CWE-690] [-Wanalyzer-possible-null-dereference]

6 months agolib/, src/: Align variable definitions
Alejandro Colomar [Sat, 26 Aug 2023 11:16:42 +0000 (13:16 +0200)] 
lib/, src/: Align variable definitions

This is just a cosmetic patch in preparation for others.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agosrc/login.c: Group preprocessor conditionals
Alejandro Colomar [Sat, 26 Aug 2023 10:35:53 +0000 (12:35 +0200)] 
src/login.c: Group preprocessor conditionals

Group them at the end of the list of variable definitions, and use
'#if defined()' instead of '#if[n]def'.  Also indent nested ones.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/defines.h: Remove ITI_AGING
Tobias Stoeckmann [Tue, 12 Dec 2023 16:37:30 +0000 (17:37 +0100)] 
lib/defines.h: Remove ITI_AGING

ITI_AGING is not set through any build environment. If it would be set,
then timings in /etc/shadow would not fit anymore.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agosrc/su.c: Fix type of variable
Alejandro Colomar [Wed, 13 Dec 2023 14:46:53 +0000 (15:46 +0100)] 
src/su.c: Fix type of variable

su.c:678:26: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘const void *’ [-Wformat=]
su.c:681:44: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘const void *’ [-Wformat=]
su.c:683:46: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘const void *’ [-Wformat=]

Reported-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/, src/: snprintf(3) already terminates strings with NUL
Alejandro Colomar [Sat, 26 Aug 2023 09:53:25 +0000 (11:53 +0200)] 
lib/, src/: snprintf(3) already terminates strings with NUL

We don't need to terminate them manually after the call.  Remove all
that paranoid code, which in some cases was even wrong.  While at it,
let's do a few more things:

-  Use sizeof(buf) for the size of the buffer.  I found that a few cases
   were passing one less byte (probably because the last one was
   manually zeroed later).  This caused a double NUL.  snprintf(3) wants
   the size of the entire buffer to properly terminate it.  Passing the
   exact value hardcoded is brittle, so use sizeof().

-  Align and improve style of variable declarations.  This makes them
   appear in this diff, which will help review the patch.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/: Use ATTR_STRING() on stpecpy() and strtcpy()
Alejandro Colomar [Sun, 26 Nov 2023 17:52:56 +0000 (18:52 +0100)] 
lib/: Use ATTR_STRING() on stpecpy() and strtcpy()

These functions consume a source string.  Document that.  There's no way
to mark that they also produce a string in dst, though.  That will be up
to the static analyzer to guess.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/attr.h: Add ATTR_STRING() attribute macro
Alejandro Colomar [Sun, 26 Nov 2023 17:38:40 +0000 (18:38 +0100)] 
lib/attr.h: Add ATTR_STRING() attribute macro

It signals that a function parameter is a string _before_ the call.

Suggested-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/, src/: Fix error handling after strto[u]l[l](3)
Alejandro Colomar [Fri, 1 Dec 2023 18:31:16 +0000 (19:31 +0100)] 
lib/, src/: Fix error handling after strto[u]l[l](3)

-  Set errno = 0 before the call.  Otherwise, it may contain anything.
-  ERANGE is not the only possible errno value of these functions.  They
   can also set it to EINVAL.
-  Any errno value after these calls is bad; just compare against 0.
-  Don't check for the return value; just errno.  This function is
   guaranteed to not modify errno on success (POSIX).
-  Check endptr == str, which may or may not set EINVAL.

Suggested-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/prefix_flag.c: Invert conditional to remove a branch
Alejandro Colomar [Fri, 1 Dec 2023 17:57:31 +0000 (18:57 +0100)] 
lib/prefix_flag.c: Invert conditional to remove a branch

This simplifies the code, and is preparation for a following commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/string/strtcpy.h: Don't use a ternary op, to silence a -Wsign-compare warning
Alejandro Colomar [Sat, 2 Sep 2023 12:33:47 +0000 (14:33 +0200)] 
lib/string/strtcpy.h: Don't use a ternary op, to silence a -Wsign-compare warning

Signed-off-by: Alejandro Colomar <alx@kernel.org>