shadow/libmisc
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
..
.indent.pro
addgrps.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
age.c
agetpass.c
audit_help.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
basename.c
btrfs.c
chkname.c
chkname.h
chowndir.c
chowntty.c
cleanup_group.c
cleanup_user.c
cleanup.c
console.c Use strlcpy(3) instead of its pattern 2022-12-22 18:03:39 -06:00
copydir.c Assume struct stat has st_atim and st_mtim fields 2022-12-22 09:49:02 -06:00
date_to_str.c Use strlcpy(3) instead of its pattern 2022-12-22 18:03:39 -06:00
entry.c
env.c
failure.c Cosmetic fixes 2022-12-22 10:31:43 +01:00
failure.h Disable utmpx permanently 2022-12-22 10:31:43 +01:00
find_new_gid.c
find_new_sub_gids.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
find_new_sub_uids.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
find_new_uid.c
getdate.h
getdate.y
getgr_nam_gid.c
getrange.c
gettime.c
hushed.c
idmapping.c
idmapping.h
isexpired.c
limits.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
list.c
log.c
loginprompt.c
mail.c
Makefile.am
motd.c
myname.c
obscure.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
pam_pass_non_interactive.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
pam_pass.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
prefix_flag.c
pwd2spwd.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
pwd_init.c
pwdcheck.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
remove_tree.c
rlogin.c
root_flag.c
salt.c
setugid.c
setupenv.c
shell.c
strtoday.c strtoday.c: remove unused defines.h inclusion 2022-12-22 10:39:45 -06:00
sub.c
sulog.c
ttytype.c
tz.c Don't redefine errno(3) 2022-12-22 11:43:29 +01:00
ulimit.c
user_busy.c Disable utmpx permanently 2022-12-22 10:31:43 +01:00
utmp.c Use strlcpy(3) instead of its pattern 2022-12-22 18:03:39 -06:00
valid.c
xgetgrgid.c
xgetgrnam.c
xgetpwnam.c
xgetpwuid.c
xgetspnam.c
xgetXXbyYY.c
xmalloc.c
yesno.c