shadow/src
Alejandro Colomar 220b352b70 Use strlcpy(3) instead of its pattern
-  Since strncpy(3) is not designed to write strings, but rather
   (null-padded) character sequences (a.k.a. unterminated strings), we
   had to manually append a '\0'.  strlcpy(3) creates strings, so they
   are always terminated.  This removes dependencies between lines, and
   also removes chances of accidents.

-  Repurposing strncpy(3) to create strings requires calculating the
   location of the terminating null byte, which involves a '-1'
   calculation.  This is a source of off-by-one bugs.  The new code has
   no '-1' calculations, so there's almost-zero chance of these bugs.

-  strlcpy(3) doesn't padd with null bytes.  Padding is relevant when
   writing fixed-width buffers to binary files, when interfacing certain
   APIs (I believe utmpx requires null padding at lease in some
   systems), or when sending them to other processes or through the
   network.  This is not the case, so padding is effectively ignored.

-  strlcpy(3) requires that the input string is really a string;
   otherwise it crashes (SIGSEGV).  Let's check if the input strings are
   really strings:

   -  lib/fields.c:
      -  'cp' was assigned from 'newft', and 'newft' comes from fgets(3).

   -  lib/gshadow.c:
      -  strlen(string) is calculated a few lines above.

   -  libmisc/console.c:
      -  'cons' comes from getdef_str, which is a bit cryptic, but seems
         to generate strings, I guess.1

   -  libmisc/date_to_str.c:
      -  It receives a string literal.  :)

   -  libmisc/utmp.c:
      -  'tname' comes from ttyname(3), which returns a string.

   -  src/su.c:
      -  'tmp_name' has been passed to strcmp(3) a few lines above.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2022-12-22 18:03:39 -06:00
..
.gitignore getsubids: system binary for user's sub*ids 2021-11-17 16:35:50 +01:00
.indent.pro
chage.c chage: Fix regression in print_date 2022-10-05 12:43:45 +02:00
check_subid_range.c Make shadow_logfd and Prog not extern 2021-12-23 15:18:07 -06:00
chfn.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
chgpasswd.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
chpasswd.c chpasswd: add IS_CRYPT_METHOD 2022-04-03 21:07:09 -05:00
chsh.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
expiry.c Assume SIGTSTP is defined 2022-12-15 16:22:05 -06:00
faillog.c Initialize local variables 2022-05-24 07:49:11 -05:00
free_subid_range.c Declare file local functions static 2022-01-03 15:09:17 +01:00
get_subid_owners.c Declare file local functions static 2022-01-03 15:09:17 +01:00
getsubids.c Declare file local functions static 2022-01-03 15:09:17 +01:00
gpasswd.c Assume SIGTSTP is defined 2022-12-15 16:22:05 -06:00
groupadd.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
groupdel.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
groupmems.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
groupmod.c Fix typos in length calculations 2022-12-22 10:34:04 +01:00
groups.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
grpck.c Declare read-only lookup pointers const 2022-01-03 15:09:17 +01:00
grpconv.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
grpunconv.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
id.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
lastlog.c lastlog: check for localtime() return value 2022-10-07 09:53:02 -05:00
login_nopam.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
login.c Cosmetic fixes 2022-12-22 10:31:43 +01:00
logoutd.c Cosmetic fixes 2022-12-22 10:31:43 +01:00
Makefile.am getsubids: system binary for user's sub*ids 2021-11-17 16:35:50 +01:00
new_subid_range.c Declare file local functions static 2022-01-03 15:09:17 +01:00
newgidmap.c Declare variable for string literal const 2022-01-03 15:09:17 +01:00
newgrp.c Remove USE_SYSLOG preprocessor conditional, which was always defined 2022-12-22 11:44:36 +01:00
newuidmap.c Declare file local functions static 2022-01-03 15:09:17 +01:00
newusers.c Don't test for NULL before calling free(3) 2022-09-29 16:03:53 +02:00
nologin.c Update licensing info 2021-12-23 19:36:50 -06:00
passwd.c Replace the deprecated getpass(3) by our agetpass() 2022-12-05 10:47:19 +01:00
pwck.c src: correct "badname" option 2022-05-06 10:13:51 -05:00
pwconv.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
pwunconv.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
su.c Use strlcpy(3) instead of its pattern 2022-12-22 18:03:39 -06:00
suauth.c Update licensing info 2021-12-23 19:36:50 -06:00
sulogin.c Remove dead code 2022-12-22 11:44:36 +01:00
useradd.c Add support for skeleton files from /usr/etc/skel 2022-12-19 09:43:03 -06:00
userdel.c Merge pull request #451 from hallyn/2021-12-05/license 2022-01-02 18:38:42 -06:00
usermod.c fix usermod -rG x y while user y is not in group x will cause user y add into group x 2022-10-06 20:29:44 -05:00
vipw.c Remove redeclared variable 2022-05-24 07:49:11 -05:00