Use STRLCPY() instead of its pattern

This makes it harder to make mistakes while editing the code.  Since the
sizeof's can be autocalculated, let the machine do that.  It also
reduces the cognitive load while reading the code.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2023-07-29 18:22:12 +02:00 committed by Iker Pedrosa
parent 370652ba05
commit 24367027d6
4 changed files with 6 additions and 5 deletions

View File

@ -13,6 +13,7 @@
#include <stdio.h>
#include "getdef.h"
#include "prototypes.h"
#include "strlcpy.h"
#ident "$Id$"
@ -44,7 +45,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
if (*cons != '/') {
char *pbuf;
strlcpy (buf, cons, sizeof (buf));
STRLCPY(buf, cons);
pbuf = &buf[0];
while ((s = strtok (pbuf, ":")) != NULL) {
if (strcmp (s, tty) == 0) {

View File

@ -24,6 +24,7 @@
#include "alloc.h"
#include "sizeof.h"
#include "strlcpy.h"
#include "zustr2stp.h"
#ident "$Id$"
@ -46,7 +47,7 @@ static bool is_my_tty (const char tty[UT_LINESIZE])
if ('\0' == tmptty[0]) {
const char *tname = ttyname (STDIN_FILENO);
if (NULL != tname)
(void) strlcpy (tmptty, tname, sizeof(tmptty));
STRLCPY(tmptty, tname);
}
if ('\0' == tmptty[0]) {

View File

@ -711,8 +711,7 @@ int main (int argc, char **argv)
sizeof (loginprompt),
_("%s login: "), hostn);
} else {
strlcpy (loginprompt, _("login: "),
sizeof (loginprompt));
STRLCPY(loginprompt, _("login: "));
}
retcode = pam_set_item (pamh, PAM_USER_PROMPT, loginprompt);

View File

@ -676,7 +676,7 @@ static /*@only@*/struct passwd * do_check_perms (void)
SYSLOG ((LOG_INFO,
"Change user from '%s' to '%s' as requested by PAM",
name, tmp_name));
if (strlcpy (name, tmp_name, sizeof(name)) >= sizeof(name)) {
if (STRLCPY(name, tmp_name) == -1) {
fprintf (stderr, _("Overlong user name '%s'\n"),
tmp_name);
SYSLOG ((LOG_NOTICE, "Overlong user name '%s'",