From: Alejandro Colomar Date: Tue, 14 Oct 2025 10:58:00 +0000 (+0200) Subject: */: s/STRTCPY/strtcpy_a/ X-Git-Tag: 4.19.0-rc1~70 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fb9f7f51a897f061fed3151b0bbc27dceb686dff;p=thirdparty%2Fshadow.git */: s/STRTCPY/strtcpy_a/ This name better reflects that it handles arrays, and doesn't shout. Signed-off-by: Alejandro Colomar --- diff --git a/lib/console.c b/lib/console.c index 7ce1a60ee..66cec2453 100644 --- a/lib/console.c +++ b/lib/console.c @@ -52,7 +52,7 @@ is_listed(const char *cfgin, const char *tty, bool def) if (*cons != '/') { char *pbuf; - STRTCPY(buf, cons); + strtcpy_a(buf, cons); pbuf = buf; while (NULL != (s = strsep(&pbuf, ":"))) { if (streq(s, tty)) { diff --git a/lib/failure.c b/lib/failure.c index a0307e65e..924c19259 100644 --- a/lib/failure.c +++ b/lib/failure.c @@ -81,7 +81,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) fl->fail_cnt++; } - STRTCPY(fl->fail_line, tty); + strtcpy_a(fl->fail_line, tty); fl->fail_time = time(NULL); /* diff --git a/lib/log.c b/lib/log.c index 10da612b9..d812b4129 100644 --- a/lib/log.c +++ b/lib/log.c @@ -81,7 +81,7 @@ void dolastlog ( ll_time = newlog.ll_time; ll_time = time(NULL); newlog.ll_time = ll_time; - STRTCPY(newlog.ll_line, line); + strtcpy_a(newlog.ll_line, line); #if HAVE_LL_HOST strncpy_a(newlog.ll_host, host); #endif diff --git a/lib/string/README b/lib/string/README index c2a7f2251..0c7c4b3f4 100644 --- a/lib/string/README +++ b/lib/string/README @@ -186,7 +186,7 @@ strcpy/ - String copying This is what the Linux kernel calls strscpy(). If you need more than one call to form a string, use stpecpy() instead. - STRTCPY() + strtcpy_a() Like strtcpy(), but takes an array. strtcat() // Unimplemented diff --git a/lib/string/strcpy/strtcpy.h b/lib/string/strcpy/strtcpy.h index d14e27f29..a440bcdfb 100644 --- a/lib/string/strcpy/strtcpy.h +++ b/lib/string/strcpy/strtcpy.h @@ -17,34 +17,8 @@ #include "sizeof.h" -/* - * SYNOPSIS - * [[gnu::null_terminated_string_arg(2)]] - * int STRTCPY(char dst[restrict], const char *restrict src); - * - * ARGUMENTS - * dst Destination buffer where to copy a string. - * src Source string to be copied into dst. - * - * DESCRIPTION - * This macro copies the string pointed to by src, into a string - * at the buffer pointed to by dst. If the destination buffer, - * isn't large enough to hold the copy, the resulting string is - * truncated. The size of the buffer is calculated internally via - * countof(). - * - * RETURN VALUE - * -1 If this call truncated the resulting string. - * - * strlen(dst) - * On success. - * - * ERRORS - * This function doesn't set errno. - */ - - -#define STRTCPY(dst, src) strtcpy(dst, src, countof(dst)) +// strtcpy_a - string truncate copy array +#define strtcpy_a(dst, src) strtcpy(dst, src, countof(dst)) ATTR_STRING(2) @@ -52,6 +26,7 @@ inline ssize_t strtcpy(char *restrict dst, const char *restrict src, size_t dsize); +// strtcpy - string truncate copy inline ssize_t strtcpy(char *restrict dst, const char *restrict src, size_t dsize) { diff --git a/src/chage.c b/src/chage.c index d1b04b4dd..f2500736f 100644 --- a/src/chage.c +++ b/src/chage.c @@ -793,7 +793,7 @@ int main (int argc, char **argv) fail_exit (E_NOPERM, process_selinux); } - STRTCPY(user_name, pw->pw_name); + strtcpy_a(user_name, pw->pw_name); #ifdef WITH_TCB if (shadowtcb_set_user (pw->pw_name) == SHADOWTCB_FAILURE) { fail_exit (E_NOPERM, process_selinux); diff --git a/src/chfn.c b/src/chfn.c index acc21a985..2fe99ac19 100644 --- a/src/chfn.c +++ b/src/chfn.c @@ -244,7 +244,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) exit (E_NOPERM); } fflg = true; - STRTCPY(fullnm, optarg); + strtcpy_a(fullnm, optarg); break; case 'h': if (!may_change_field ('h')) { @@ -253,7 +253,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) exit (E_NOPERM); } hflg = true; - STRTCPY(homeph, optarg); + strtcpy_a(homeph, optarg); break; case 'o': if (!amroot) { @@ -267,7 +267,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) _("%s: fields too long\n"), Prog); exit (E_NOPERM); } - STRTCPY(slop, optarg); + strtcpy_a(slop, optarg); break; case 'r': if (!may_change_field ('r')) { @@ -276,7 +276,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) exit (E_NOPERM); } rflg = true; - STRTCPY(roomno, optarg); + strtcpy_a(roomno, optarg); break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; @@ -291,7 +291,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) exit (E_NOPERM); } wflg = true; - STRTCPY(workph, optarg); + strtcpy_a(workph, optarg); break; default: usage (E_USAGE); @@ -483,7 +483,7 @@ static void get_old_fields (const char *gecos) char old_gecos[BUFSIZ]; const char *f; - STRTCPY(old_gecos, gecos); + strtcpy_a(old_gecos, gecos); p = old_gecos; f = strsep(&p, ","); diff --git a/src/chsh.c b/src/chsh.c index bb65a82d6..ce5f5b46e 100644 --- a/src/chsh.c +++ b/src/chsh.c @@ -242,7 +242,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) break; case 's': sflg = true; - STRTCPY(loginsh, optarg); + strtcpy_a(loginsh, optarg); break; default: usage (E_USAGE); @@ -524,7 +524,7 @@ int main (int argc, char **argv) * file, or use the value from the command line. */ if (!sflg) { - STRTCPY(loginsh, pw->pw_shell); + strtcpy_a(loginsh, pw->pw_shell); } /* diff --git a/src/gpasswd.c b/src/gpasswd.c index 1224d80a8..14ffedb81 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -822,7 +822,7 @@ static void change_passwd (struct group *gr) exit (1); } - STRTCPY(pass, cp); + strtcpy_a(pass, cp); erase_pass (cp); cp = agetpass (_("Re-enter new password: ")); if (NULL == cp) { diff --git a/src/login.c b/src/login.c index dfc0f96c6..2fa940748 100644 --- a/src/login.c +++ b/src/login.c @@ -517,7 +517,7 @@ int main (int argc, char **argv) if (NULL == tmptty) { tmptty = "UNKNOWN"; } - STRTCPY(tty, tmptty); + strtcpy_a(tty, tmptty); #ifndef USE_PAM is_console = console (tty); @@ -646,7 +646,7 @@ int main (int argc, char **argv) if (gethostname (hostn, sizeof (hostn)) == 0) { stprintf_a(loginprompt, _("%s login: "), hostn); } else { - STRTCPY(loginprompt, _("login: ")); + strtcpy_a(loginprompt, _("login: ")); } retcode = pam_set_item (pamh, PAM_USER_PROMPT, loginprompt); diff --git a/src/passwd.c b/src/passwd.c index c44f404a3..f6c4f47a4 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -233,7 +233,7 @@ static int new_password (const struct passwd *pw) pw->pw_name); return -1; } - STRTCPY(orig, clear); + strtcpy_a(orig, clear); erase_pass (clear); strzero (cipher); } else { @@ -292,7 +292,7 @@ static int new_password (const struct passwd *pw) if (NULL == cp) { return -1; } - ret = STRTCPY (pass, cp); + ret = strtcpy_a(pass, cp); erase_pass (cp); if (ret == -1) { (void) fputs (_("Password is too long.\n"), stderr); @@ -311,7 +311,7 @@ static int new_password (const struct passwd *pw) if (warned && !streq(pass, cp)) { warned = false; } - ret = STRTCPY (pass, cp); + ret = strtcpy_a(pass, cp); erase_pass (cp); if (ret == -1) { (void) fputs (_("Password is too long.\n"), stderr); @@ -373,7 +373,7 @@ static int new_password (const struct passwd *pw) return -1; } - STRTCPY(crypt_passwd, cp); + strtcpy_a(crypt_passwd, cp); return 0; } @@ -1065,7 +1065,7 @@ main(int argc, char **argv) * If there are no other flags, just change the password. */ if (!anyflag) { - STRTCPY(crypt_passwd, cp); + strtcpy_a(crypt_passwd, cp); /* * See if the user is permitted to change the password. diff --git a/src/su.c b/src/su.c index 2cfb2cf56..5ba80e649 100644 --- a/src/su.c +++ b/src/su.c @@ -686,7 +686,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 (STRTCPY(name, tmp_name) == -1) { + if (strtcpy_a(name, tmp_name) == -1) { fprintf (stderr, _("Overlong user name '%s'\n"), tmp_name); SYSLOG ((LOG_NOTICE, "Overlong user name '%s'", @@ -785,7 +785,7 @@ save_caller_context(void) (unsigned long) caller_uid)); su_failure (caller_tty, true); /* unknown target UID*/ } - STRTCPY(caller_name, pw->pw_name); + strtcpy_a(caller_name, pw->pw_name); #ifndef USE_PAM #ifdef SU_ACCESS @@ -861,7 +861,7 @@ static void process_flags (int argc, char **argv) } if (optind < argc) { - STRTCPY(name, argv[optind++]); /* use this login id */ + strtcpy_a(name, argv[optind++]); /* use this login id */ } if (streq(name, "")) { /* use default user */ struct passwd *root_pw = getpwnam ("root"); diff --git a/tests/unit/test_strtcpy.c b/tests/unit/test_strtcpy.c index 6b793fcbc..5e292caaf 100644 --- a/tests/unit/test_strtcpy.c +++ b/tests/unit/test_strtcpy.c @@ -18,16 +18,16 @@ #include "string/strcpy/strtcpy.h" -static void test_STRTCPY_trunc(void **state); -static void test_STRTCPY_ok(void **state); +static void test_strtcpy_a_trunc(void **state); +static void test_strtcpy_a_ok(void **state); int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(test_STRTCPY_trunc), - cmocka_unit_test(test_STRTCPY_ok), + cmocka_unit_test(test_strtcpy_a_trunc), + cmocka_unit_test(test_strtcpy_a_ok), }; return cmocka_run_group_tests(tests, NULL, NULL); @@ -35,33 +35,33 @@ main(void) static void -test_STRTCPY_trunc(void **state) +test_strtcpy_a_trunc(void **state) { char buf[countof("foo")]; // Test that we're not returning SIZE_MAX - assert_true(STRTCPY(buf, "fooo") < 0); + assert_true(strtcpy_a(buf, "fooo") < 0); assert_string_equal(buf, "foo"); - assert_int_equal(STRTCPY(buf, "barbaz"), -1); + assert_int_equal(strtcpy_a(buf, "barbaz"), -1); assert_string_equal(buf, "bar"); } static void -test_STRTCPY_ok(void **state) +test_strtcpy_a_ok(void **state) { char buf[countof("foo")]; - assert_int_equal(STRTCPY(buf, "foo"), strlen("foo")); + assert_int_equal(strtcpy_a(buf, "foo"), strlen("foo")); assert_string_equal(buf, "foo"); - assert_int_equal(STRTCPY(buf, "fo"), strlen("fo")); + assert_int_equal(strtcpy_a(buf, "fo"), strlen("fo")); assert_string_equal(buf, "fo"); - assert_int_equal(STRTCPY(buf, "f"), strlen("f")); + assert_int_equal(strtcpy_a(buf, "f"), strlen("f")); assert_string_equal(buf, "f"); - assert_int_equal(STRTCPY(buf, ""), strlen("")); + assert_int_equal(strtcpy_a(buf, ""), strlen("")); assert_string_equal(buf, ""); }