diff --git a/configure.ac b/configure.ac index 71697e7aae..98b3d38aa2 100644 --- a/configure.ac +++ b/configure.ac @@ -47,7 +47,7 @@ AC_CHECK_FUNCS([arc4random_buf \ updwtmpx innetgr \ getspnam_r \ rpmatch \ - memset_explicit explicit_bzero stpecpy stpeprintf]) + memset_explicit explicit_bzero stpecpy seprintf]) AC_SYS_LARGEFILE dnl Checks for typedefs, structures, and compiler characteristics. diff --git a/lib/Makefile.am b/lib/Makefile.am index 60c4948d80..2dbc0e3baf 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -213,10 +213,10 @@ libshadow_la_SOURCES = \ string/memset/memzero.h \ string/sprintf/aprintf.c \ string/sprintf/aprintf.h \ - string/sprintf/snprintf.c \ - string/sprintf/snprintf.h \ - string/sprintf/stpeprintf.c \ - string/sprintf/stpeprintf.h \ + string/sprintf/seprintf.c \ + string/sprintf/seprintf.h \ + string/sprintf/stprintf.c \ + string/sprintf/stprintf.h \ string/strchr/strchrcnt.c \ string/strchr/strchrcnt.h \ string/strchr/strchrscnt.c \ @@ -239,6 +239,8 @@ libshadow_la_SOURCES = \ string/strcpy/strncat.h \ string/strcpy/strncpy.c \ string/strcpy/strncpy.h \ + string/strcpy/strtcat.c \ + string/strcpy/strtcat.h \ string/strcpy/strtcpy.c \ string/strcpy/strtcpy.h \ string/strdup/strdup.c \ diff --git a/lib/audit_help.c b/lib/audit_help.c index 68835091e0..748b092913 100644 --- a/lib/audit_help.c +++ b/lib/audit_help.c @@ -25,7 +25,7 @@ #include "attr.h" #include "prototypes.h" #include "shadowlog.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" int audit_fd; @@ -104,10 +104,10 @@ audit_logger_with_group(int type, const char *op, const char *name, len = strnlen(grp, sizeof(enc_group)/2); if (audit_value_needs_encoding(grp, len)) { - SNPRINTF(buf, "%s %s=%s", op, grp_type, + STPRINTF(buf, "%s %s=%s", op, grp_type, audit_encode_value(enc_group, grp, len)); } else { - SNPRINTF(buf, "%s %s=\"%s\"", op, grp_type, grp); + STPRINTF(buf, "%s %s=\"%s\"", op, grp_type, grp); } audit_log_acct_message(audit_fd, type, NULL, buf, name, id, diff --git a/lib/commonio.c b/lib/commonio.c index 73afa6098d..363dd5dd78 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -36,7 +36,7 @@ #include "sssd.h" #include "string/memset/memzero.h" #include "string/sprintf/aprintf.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" #include "string/strerrno.h" @@ -140,7 +140,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) } pid = getpid (); - SNPRINTF(buf, "%lu", (unsigned long) pid); + STPRINTF(buf, "%lu", (unsigned long) pid); len = (ssize_t) strlen (buf) + 1; if (write_full(fd, buf, len) == -1) { if (log) { @@ -340,7 +340,7 @@ static void free_linked_list (struct commonio_db *db) int commonio_setname (struct commonio_db *db, const char *name) { - SNPRINTF(db->filename, "%s", name); + STPRINTF(db->filename, "%s", name); db->setname = true; return 1; } @@ -486,7 +486,7 @@ int commonio_unlock (struct commonio_db *db, bool process_selinux) * then call ulckpwdf() (if used) on last unlock. */ db->locked = false; - SNPRINTF(lock, "%s.lock", db->filename); + STPRINTF(lock, "%s.lock", db->filename); unlink (lock); dec_lock_count (); return 1; @@ -916,7 +916,7 @@ int commonio_close (struct commonio_db *db, bool process_selinux) /* * Create backup file. */ - if (SNPRINTF(buf, "%s-", db->filename) == -1) { + if (STPRINTF(buf, "%s-", db->filename) == -1) { (void) fclose (db->fp); db->fp = NULL; goto fail; @@ -955,7 +955,7 @@ int commonio_close (struct commonio_db *db, bool process_selinux) sb.st_gid = db->st_gid; } - if (SNPRINTF(buf, "%s+", db->filename) == -1) + if (STPRINTF(buf, "%s+", db->filename) == -1) goto fail; #ifdef WITH_SELINUX diff --git a/lib/env.c b/lib/env.c index 91424087d9..df643c33ee 100644 --- a/lib/env.c +++ b/lib/env.c @@ -22,8 +22,7 @@ #include "defines.h" #include "shadowlog.h" #include "string/sprintf/aprintf.h" -#include "string/sprintf/snprintf.h" -#include "string/sprintf/aprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/strprefix.h" #include "string/strdup/strdup.h" @@ -170,7 +169,7 @@ void set_env (int argc, char *const *argv) cp = strchr (*argv, '='); if (NULL == cp) { - assert(SNPRINTF(variable, "L%d", noname) != -1); + assert(STPRINTF(variable, "L%d", noname) != -1); noname++; addenv (variable, *argv); } else { diff --git a/lib/get_pid.c b/lib/get_pid.c index 7f80b16459..237a727b12 100644 --- a/lib/get_pid.c +++ b/lib/get_pid.c @@ -14,7 +14,7 @@ #include "atoi/getnum.h" #include "defines.h" #include "prototypes.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strerrno.h" @@ -59,8 +59,8 @@ int open_pidfd(const char *pidstr) if (get_pid(pidstr, &target) == -1) return -ENOENT; - if (SNPRINTF(proc_dir_name, "/proc/%d/", target) == -1) { - fprintf(stderr, "snprintf of proc path failed for %d: %s\n", + if (STPRINTF(proc_dir_name, "/proc/%d/", target) == -1) { + fprintf(stderr, "stprintf of proc path failed for %d: %s\n", target, strerrno()); return -EINVAL; } diff --git a/lib/hushed.c b/lib/hushed.c index 56add9e964..52514e40d1 100644 --- a/lib/hushed.c +++ b/lib/hushed.c @@ -20,7 +20,7 @@ #include "defines.h" #include "getdef.h" #include "prototypes.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strtok/stpsep.h" @@ -60,7 +60,7 @@ bool hushed (const char *username) */ if (hushfile[0] != '/') { - SNPRINTF(buf, "%s/%s", pw->pw_dir, hushfile); + STPRINTF(buf, "%s/%s", pw->pw_dir, hushfile); return (access (buf, F_OK) == 0); } diff --git a/lib/idmapping.c b/lib/idmapping.c index bd9dbd8a7a..1bf9b59922 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -26,7 +26,7 @@ #include "prototypes.h" #include "shadowlog.h" #include "sizeof.h" -#include "string/sprintf/stpeprintf.h" +#include "string/sprintf/seprintf.h" #include "string/strcmp/streq.h" #include "string/strerrno.h" @@ -183,13 +183,13 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings mapping = mappings; for (idx = 0; idx < ranges; idx++, mapping++) { /* Append this range to the string that will be written */ - pos = stpeprintf(pos, end, "%lu %lu %lu\n", + pos = seprintf(pos, end, "%lu %lu %lu\n", mapping->upper, mapping->lower, mapping->count); } if (pos == end || pos == NULL) { - fprintf(log_get_logfd(), _("%s: stpeprintf failed!\n"), log_get_progname()); + fprintf(log_get_logfd(), _("%s: seprintf failed!\n"), log_get_progname()); exit(EXIT_FAILURE); } diff --git a/lib/nss.c b/lib/nss.c index 9f30b0a110..5708ab6c9b 100644 --- a/lib/nss.c +++ b/lib/nss.c @@ -14,7 +14,7 @@ #include "../libsubid/subid.h" #include "shadowlog_internal.h" #include "shadowlog.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/strcaseprefix.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" @@ -109,7 +109,7 @@ nss_init(const char *nsswitch_path) { fprintf(shadow_logfd, "Using files\n"); goto null_subid; } - SNPRINTF(libname, "libsubid_%s.so", p); + STPRINTF(libname, "libsubid_%s.so", p); h = dlopen(libname, RTLD_LAZY); if (!h) { fprintf(shadow_logfd, "Error opening %s: %s\n", libname, dlerror()); diff --git a/lib/pwauth.c b/lib/pwauth.c index 3a2ccb2965..b02bc0f8ba 100644 --- a/lib/pwauth.c +++ b/lib/pwauth.c @@ -25,7 +25,7 @@ #include "pwauth.h" #include "getdef.h" #include "string/memset/memzero.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #ifdef SKEY @@ -111,7 +111,7 @@ pw_auth(const char *cipher, const char *user) } #endif - SNPRINTF(prompt, cp, user); + STPRINTF(prompt, cp, user); clear = agetpass(prompt); input = (clear == NULL) ? "" : clear; diff --git a/lib/salt.c b/lib/salt.c index 1efeb2cec3..09e7de8d50 100644 --- a/lib/salt.c +++ b/lib/salt.c @@ -26,7 +26,9 @@ #include "getdef.h" #include "prototypes.h" #include "shadowlog.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" +#include "string/strcpy/strtcat.h" #if (defined CRYPT_GENSALT_IMPLEMENTS_AUTO_ENTROPY && \ @@ -177,7 +179,7 @@ static /*@observer@*/void SHA_salt_rounds_to_buf (char *buf, unsigned long round */ assert (GENSALT_SETTING_SIZE > buf_begin + 17); - (void) snprintf (buf + buf_begin, 18, "rounds=%lu$", rounds); + stprintf(buf + buf_begin, 18, "rounds=%lu$", rounds); } #endif /* USE_SHA_CRYPT */ @@ -256,7 +258,7 @@ static /*@observer@*/void BCRYPT_salt_rounds_to_buf (char *buf, unsigned long ro */ assert (GENSALT_SETTING_SIZE > buf_begin + 3); - (void) snprintf (buf + buf_begin, 4, "%2.2lu$", rounds); + stprintf(buf + buf_begin, 4, "%2.2lu$", rounds); } #endif /* USE_BCRYPT */ @@ -443,12 +445,8 @@ static /*@observer@*/const char *gensalt (size_t salt_size) return retval; #else /* USE_XCRYPT_GENSALT */ - /* Check if the result buffer is long enough. */ - assert (GENSALT_SETTING_SIZE > strlen (result) + salt_len); - /* Concatenate a pseudo random salt. */ - strncat (result, gensalt (salt_len), - GENSALT_SETTING_SIZE - strlen (result) - 1); + assert(strtcat_a(result, gensalt(salt_len)) != -1); return result; #endif /* USE_XCRYPT_GENSALT */ diff --git a/lib/shell.c b/lib/shell.c index 40b840ee95..2aec7e0970 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -15,7 +15,7 @@ #include #include "prototypes.h" #include "defines.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" extern char **newenvp; @@ -48,7 +48,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[]) * don't want to tell us what it is themselves. */ if (arg == NULL) { - SNPRINTF(arg0, "-%s", Basename(file)); + STPRINTF(arg0, "-%s", Basename(file)); arg = arg0; } @@ -74,7 +74,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[]) * how to execute this stupid shell, so I might as well give * up in disgust ... */ - SNPRINTF(arg0, _("Cannot execute %s"), file); + STPRINTF(arg0, _("Cannot execute %s"), file); errno = err; perror (arg0); return err; diff --git a/lib/string/README b/lib/string/README index 147b278fd4..262c035e61 100644 --- a/lib/string/README +++ b/lib/string/README @@ -189,10 +189,10 @@ strcpy/ - String copying STRTCPY() Like strtcpy(), but takes an array. - strtcat() // Unimplemented + strtcat() Catenate a string after an existing string, with truncation. Rarely useful. Consider using stpecpy() instead. - STRTCAT() // Unimplemented + strtcat_a() Like strtcat(), but takes an array. stpecpy() @@ -209,14 +209,14 @@ sprintf/ - Formatted string creation sprintf(3) variant that allocates. It has better interface than asprintf(3). - stprintf() // Current name: snprintf_() + stprintf() snprintf(3) wrapper that reports truncation with -1. If you need more than one call to form a string, use seprintf() instead. - STPRINTF() // Current name: SNPRINTF() + STPRINTF() Like stprintf(), but takes an array. - seprintf() // Current name: stpeprintf()) + seprintf() Similar to stprintf(), but takes a pointer to the end instead of a size. This makes it safer for chaining several calls. diff --git a/lib/string/sprintf/seprintf.c b/lib/string/sprintf/seprintf.c new file mode 100644 index 0000000000..2fdfdfbf98 --- /dev/null +++ b/lib/string/sprintf/seprintf.c @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include "config.h" + +#include "string/sprintf/seprintf.h" + +#include + + +#if !defined(HAVE_SEPRINTF) +extern inline char *seprintf(char *dst, const char *end, + const char *restrict fmt, ...); +extern inline char *vseprintf(char *dst, const char *end, + const char *restrict fmt, va_list ap); +#endif diff --git a/lib/string/sprintf/seprintf.h b/lib/string/sprintf/seprintf.h new file mode 100644 index 0000000000..b2059fb266 --- /dev/null +++ b/lib/string/sprintf/seprintf.h @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_SEPRINTF_H_ +#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_SEPRINTF_H_ + + +#include "config.h" + +#include +#include + +#include "attr.h" +#include "string/sprintf/stprintf.h" + + +#if !defined(HAVE_SEPRINTF) +// seprintf - string end-pointer print formatted +format_attr(printf, 3, 4) +inline char *seprintf(char *dst, const char *end, const char *restrict fmt, + ...); +// vseprintf - va_list string end-pointer print formatted +format_attr(printf, 3, 0) +inline char *vseprintf(char *dst, const char *end, const char *restrict fmt, + va_list ap); +#endif + + +#if !defined(HAVE_SEPRINTF) +inline char * +seprintf(char *dst, const char *end, const char *restrict fmt, ...) +{ + char *p; + va_list ap; + + va_start(ap, fmt); + p = vseprintf(dst, end, fmt, ap); + va_end(ap); + + return p; +} +#endif + + +#if !defined(HAVE_SEPRINTF) +inline char * +vseprintf(char *dst, const char *end, const char *restrict fmt, va_list ap) +{ + int len; + ptrdiff_t size; + + if (dst == NULL) + return NULL; + + size = end - dst; + len = vstprintf(dst, size, fmt, ap); + if (len == -1) + return NULL; + + return dst + len; +} +#endif + + +#endif // include guard diff --git a/lib/string/sprintf/snprintf.c b/lib/string/sprintf/snprintf.c deleted file mode 100644 index e3755da76b..0000000000 --- a/lib/string/sprintf/snprintf.c +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar -// SPDX-License-Identifier: BSD-3-Clause - - -#include "config.h" - -#include "string/sprintf/snprintf.h" - -#include -#include - - -extern inline int snprintf_(char *restrict s, size_t size, - const char *restrict fmt, ...); -extern inline int vsnprintf_(char *restrict s, size_t size, - const char *restrict fmt, va_list ap); diff --git a/lib/string/sprintf/snprintf.h b/lib/string/sprintf/snprintf.h deleted file mode 100644 index 94f7ee3ca5..0000000000 --- a/lib/string/sprintf/snprintf.h +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar -// SPDX-License-Identifier: BSD-3-Clause - - -#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_ -#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_ - - -#include "config.h" - -#include -#include -#include - -#include "attr.h" -#include "sizeof.h" - - -#define SNPRINTF(s, fmt, ...) \ -( \ - snprintf_(s, countof(s), fmt __VA_OPT__(,) __VA_ARGS__) \ -) - - -format_attr(printf, 3, 4) -inline int snprintf_(char *restrict s, size_t size, const char *restrict fmt, - ...); -format_attr(printf, 3, 0) -inline int vsnprintf_(char *restrict s, size_t size, const char *restrict fmt, - va_list ap); - - -inline int -snprintf_(char *restrict s, size_t size, const char *restrict fmt, ...) -{ - int len; - va_list ap; - - va_start(ap, fmt); - len = vsnprintf_(s, size, fmt, ap); - va_end(ap); - - return len; -} - - -inline int -vsnprintf_(char *restrict s, size_t size, const char *restrict fmt, va_list ap) -{ - int len; - - len = vsnprintf(s, size, fmt, ap); - if (len == -1) - return -1; - if ((size_t) len >= size) - return -1; - - return len; -} - - -#endif // include guard diff --git a/lib/string/sprintf/stpeprintf.c b/lib/string/sprintf/stpeprintf.c deleted file mode 100644 index d195931b89..0000000000 --- a/lib/string/sprintf/stpeprintf.c +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar -// SPDX-License-Identifier: BSD-3-Clause - - -#include "config.h" - -#include "string/sprintf/stpeprintf.h" - -#include - - -#if !defined(HAVE_STPEPRINTF) -extern inline char *stpeprintf(char *dst, char *end, const char *restrict fmt, - ...); -extern inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt, - va_list ap); -#endif diff --git a/lib/string/sprintf/stpeprintf.h b/lib/string/sprintf/stpeprintf.h deleted file mode 100644 index b0048c4441..0000000000 --- a/lib/string/sprintf/stpeprintf.h +++ /dev/null @@ -1,118 +0,0 @@ -// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar -// SPDX-License-Identifier: BSD-3-Clause - - -#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPEPRINTF_H_ -#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPEPRINTF_H_ - - -#include "config.h" - -#include -#include -#include - -#include "attr.h" - - -#if !defined(HAVE_STPEPRINTF) -format_attr(printf, 3, 4) -inline char *stpeprintf(char *dst, char *end, const char *restrict fmt, ...); -format_attr(printf, 3, 0) -inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt, - va_list ap); -#endif - - -/* - * SYNOPSIS - * [[gnu::format(printf, 3, 4)]] - * char *_Nullable stpeprintf(char *_Nullable dst, char end[0], - * const char *restrict fmt, ...); - * - * [[gnu::format(printf, 3, 0)]] - * char *_Nullable vstpeprintf(char *_Nullable dst, char end[0], - * const char *restrict fmt, va_list ap); - * - * - * ARGUMENTS - * dst Destination buffer where to write a string. - * - * end Pointer to one after the last element of the buffer - * pointed to by `dst`. Usually, it should be calculated - * as `dst + countof(dst)`. - * - * fmt Format string - * - * ... - * ap Variadic argument list - * - * DESCRIPTION - * These functions are very similar to [v]snprintf(3). - * - * The destination buffer is limited by a pointer to its end --one - * after its last element-- instead of a size. This allows - * chaining calls to it safely, unlike [v]snprintf(3), which is - * difficult to chain without invoking Undefined Behavior. - * - * RETURN VALUE - * dst + strlen(dst) - * • On success, these functions return a pointer to the - * terminating NUL byte. - * - * end - * • If this call truncated the resulting string. - * • If `dst == end` (a previous chained call to these - * functions truncated). - * NULL - * • If this function failed (see ERRORS). - * • If `dst == NULL` (a previous chained call to these - * functions failed). - * - * ERRORS - * These functions may fail for the same reasons as vsnprintf(3). - */ - - -#if !defined(HAVE_STPEPRINTF) -inline char * -stpeprintf(char *dst, char *end, const char *restrict fmt, ...) -{ - char *p; - va_list ap; - - va_start(ap, fmt); - p = vstpeprintf(dst, end, fmt, ap); - va_end(ap); - - return p; -} -#endif - - -#if !defined(HAVE_STPEPRINTF) -inline char * -vstpeprintf(char *dst, char *end, const char *restrict fmt, va_list ap) -{ - int len; - ptrdiff_t size; - - if (dst == end) - return end; - if (dst == NULL) - return NULL; - - size = end - dst; - len = vsnprintf(dst, size, fmt, ap); - - if (len == -1) - return NULL; - if (len >= size) - return end; - - return dst + len; -} -#endif - - -#endif // include guard diff --git a/lib/string/sprintf/stprintf.c b/lib/string/sprintf/stprintf.c new file mode 100644 index 0000000000..735eb056f1 --- /dev/null +++ b/lib/string/sprintf/stprintf.c @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include "config.h" + +#include "string/sprintf/stprintf.h" + +#include + + +extern inline int stprintf(char *restrict s, int size, + const char *restrict fmt, ...); +extern inline int vstprintf(char *restrict s, int size, + const char *restrict fmt, va_list ap); diff --git a/lib/string/sprintf/stprintf.h b/lib/string/sprintf/stprintf.h new file mode 100644 index 0000000000..264abe81a2 --- /dev/null +++ b/lib/string/sprintf/stprintf.h @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPRINTF_H_ +#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPRINTF_H_ + + +#include "config.h" + +#include +#include +#include + +#include "attr.h" +#include "sizeof.h" + + +#define STPRINTF(s, fmt, ...) \ +( \ + stprintf(s, countof(s), fmt __VA_OPT__(,) __VA_ARGS__) \ +) + + +// stprintf - string truncate print formatted +format_attr(printf, 3, 4) +inline int stprintf(char *restrict s, int size, const char *restrict fmt, ...); +// vstprintf - va_list string truncate print formatted +format_attr(printf, 3, 0) +inline int vstprintf(char *restrict s, int size, const char *restrict fmt, + va_list ap); + + +inline int +stprintf(char *restrict s, int size, const char *restrict fmt, ...) +{ + int len; + va_list ap; + + va_start(ap, fmt); + len = vstprintf(s, size, fmt, ap); + va_end(ap); + + return len; +} + + +inline int +vstprintf(char *restrict s, int size, const char *restrict fmt, va_list ap) +{ + int len; + + len = vsnprintf(s, size, fmt, ap); + if (len == -1) + return -1; + if (len >= size) { + errno = E2BIG; + return -1; + } + + return len; +} + + +#endif // include guard diff --git a/lib/string/strcpy/stpecpy.c b/lib/string/strcpy/stpecpy.c index 2e6f92b0fc..878853e79f 100644 --- a/lib/string/strcpy/stpecpy.c +++ b/lib/string/strcpy/stpecpy.c @@ -8,5 +8,6 @@ #if !defined(HAVE_STPECPY) -extern inline char *stpecpy(char *dst, char *end, const char *restrict src); +extern inline char *stpecpy(char *dst, const char *end, + const char *restrict src); #endif diff --git a/lib/string/strcpy/stpecpy.h b/lib/string/strcpy/stpecpy.h index 91c6ce7a7f..c2471d4daa 100644 --- a/lib/string/strcpy/stpecpy.h +++ b/lib/string/strcpy/stpecpy.h @@ -8,79 +8,36 @@ #include "config.h" +#include #include #include #include #include "attr.h" +#include "string/strcpy/strtcpy.h" #if !defined(HAVE_STPECPY) +// stpecpy - string offset-pointer end-pointer copy ATTR_STRING(3) -inline char *stpecpy(char *dst, char *end, const char *restrict src); +inline char *stpecpy(char *dst, const char *end, const char *restrict src); #endif -/* - * SYNOPSIS - * [[gnu::null_terminated_string_arg(3)]] - * char *_Nullable stpecpy(char *_Nullable dst, char end[0], - * const char *restrict src); - * - * ARGUMENTS - * dst Destination buffer where to copy a string. - * - * end Pointer to one after the last element of the buffer - * pointed to by `dst`. Usually, it should be calculated - * as `dst + countof(dst)`. - * - * src Source string to be copied into dst. - * - * DESCRIPTION - * This function copies the string pointed to by src, into a string - * at the buffer pointed to by dst. If the destination buffer, - * limited by a pointer to its end --one after its last element--, - * isn't large enough to hold the copy, the resulting string is - * truncated. - * - * This function can be chained with calls to [v]stpeprintf(). - * - * RETURN VALUE - * dst + strlen(dst) - * • On success, this function returns a pointer to the - * terminating NUL byte. - * - * end - * • If this call truncated the resulting string. - * • If `dst == end` (a previous chained call to these - * functions truncated). - * NULL - * • If `dst == NULL` (a previous chained call to - * [v]stpeprintf() failed). - * - * ERRORS - * This function doesn't set errno. - */ - - #if !defined(HAVE_STPECPY) inline char * -stpecpy(char *dst, char *end, const char *restrict src) +stpecpy(char *dst, const char *end, const char *restrict src) { - bool trunc; - size_t dsize, dlen, slen; + ssize_t dlen; - if (dst == end) - return end; if (dst == NULL) return NULL; - dsize = end - dst; - slen = strnlen(src, dsize); - trunc = (slen == dsize); - dlen = slen - trunc; + dlen = strtcpy(dst, src, end - dst); + if (dlen == -1) + return NULL; - return stpcpy(mempcpy(dst, src, dlen), "") + trunc; + return dst + dlen; } #endif diff --git a/lib/string/strcpy/strtcat.c b/lib/string/strcpy/strtcat.c new file mode 100644 index 0000000000..d89896794a --- /dev/null +++ b/lib/string/strcpy/strtcat.c @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: 2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include "config.h" + +#include "string/strcpy/strtcat.h" + +#include + + +extern inline ssize_t strtcat(char *restrict dst, const char *restrict src, + size_t dsize); diff --git a/lib/string/strcpy/strtcat.h b/lib/string/strcpy/strtcat.h new file mode 100644 index 0000000000..6d879e7f90 --- /dev/null +++ b/lib/string/strcpy/strtcat.h @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRING_STRCPY_STRTCAT_H_ +#define SHADOW_INCLUDE_LIB_STRING_STRCPY_STRTCAT_H_ + + +#include "config.h" + +#include + +#include "attr.h" +#include "sizeof.h" +#include "string/strchr/strnul.h" +#include "string/strcpy/stpecpy.h" + + +// strtcat_a - string truncate catenate array +#define strtcat_a(dst, src) strtcat(dst, src, countof(dst)) + + +ATTR_STRING(2) +inline ssize_t strtcat(char *restrict dst, const char *restrict src, + size_t dsize); + + +// strtcat - string truncate catenate +// Returns new length, or -1 on truncation. +inline ssize_t +strtcat(char *restrict dst, const char *restrict src, size_t dsize) +{ + char *p, *end; + + end = dst + dsize; + + p = stpecpy(strnul(dst), end, src); + if (p == NULL) + return -1; + + return p - dst; +} + + +#endif // include guard diff --git a/lib/string/strcpy/strtcpy.h b/lib/string/strcpy/strtcpy.h index d14e27f299..06e1c77af4 100644 --- a/lib/string/strcpy/strtcpy.h +++ b/lib/string/strcpy/strtcpy.h @@ -8,6 +8,7 @@ #include "config.h" +#include #include #include #include @@ -67,8 +68,10 @@ strtcpy(char *restrict dst, const char *restrict src, size_t dsize) stpcpy(mempcpy(dst, src, dlen), ""); - if (trunc) + if (trunc) { + errno = E2BIG; return -1; + } return slen; } diff --git a/lib/subordinateio.c b/lib/subordinateio.c index 0ceeecafd4..9744e08142 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -24,7 +24,7 @@ #include "alloc/reallocf.h" #include "atoi/str2i.h" #include "string/ctype/strisascii/strisdigit.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strtok/strsep2arr.h" @@ -226,7 +226,7 @@ static const struct subordinate_range *find_range(struct commonio_db *db, return NULL; } owner_uid = pwd->pw_uid; - if (SNPRINTF(owner_uid_string, "%lu", (unsigned long) owner_uid) == -1) + if (STPRINTF(owner_uid_string, "%lu", (unsigned long) owner_uid) == -1) return NULL; commonio_rewind(db); @@ -828,7 +828,6 @@ static bool get_owner_id(const char *owner, enum subid_type id_type, char *id) { struct passwd *pw; struct group *gr; - int ret = 0; switch (id_type) { case ID_TYPE_UID: @@ -836,20 +835,16 @@ static bool get_owner_id(const char *owner, enum subid_type id_type, char *id) if (pw == NULL) { return false; } - ret = snprintf(id, ID_SIZE, "%u", pw->pw_uid); - if (ret < 0 || ret >= ID_SIZE) { + if (stprintf(id, ID_SIZE, "%u", pw->pw_uid) == -1) return false; - } break; case ID_TYPE_GID: gr = getgrnam(owner); if (gr == NULL) { return false; } - ret = snprintf(id, ID_SIZE, "%u", gr->gr_gid); - if (ret < 0 || ret >= ID_SIZE) { + if (stprintf(id, ID_SIZE, "%u", gr->gr_gid) == -1) return false; - } break; default: return false; diff --git a/lib/user_busy.c b/lib/user_busy.c index 51f0a9ea37..0f17e92a20 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -27,7 +27,7 @@ #include "subordinateio.h" #endif /* ENABLE_SUBIDS */ #include "shadowlog.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strneq.h" #include "string/strcmp/strprefix.h" @@ -98,7 +98,7 @@ static int different_namespace (const char *sname) char path[41]; char buf[512], buf2[512]; - SNPRINTF(path, "/proc/%s/ns/user", sname); + STPRINTF(path, "/proc/%s/ns/user", sname); if (READLINKNUL(path, buf) == -1) return 0; @@ -121,7 +121,7 @@ static int check_status (const char *name, const char *sname, uid_t uid) char line[1024]; FILE *sfile; - SNPRINTF(status, "/proc/%s/status", sname); + STPRINTF(status, "/proc/%s/status", sname); sfile = fopen (status, "r"); if (NULL == sfile) { @@ -214,7 +214,7 @@ static int user_busy_processes (const char *name, uid_t uid) } /* Check if the process is in our chroot */ - SNPRINTF(root_path, "/proc/%lu/root", (unsigned long) pid); + STPRINTF(root_path, "/proc/%lu/root", (unsigned long) pid); if (stat (root_path, &sbroot_process) != 0) { continue; } @@ -234,7 +234,7 @@ static int user_busy_processes (const char *name, uid_t uid) return 1; } - SNPRINTF(task_path, "/proc/%lu/task", (unsigned long) pid); + STPRINTF(task_path, "/proc/%lu/task", (unsigned long) pid); task_dir = opendir (task_path); if (task_dir != NULL) { while (NULL != (ent = readdir(task_dir))) { diff --git a/po/bs.po b/po/bs.po index 353f8b0f16..02032ed42b 100644 --- a/po/bs.po +++ b/po/bs.po @@ -211,7 +211,7 @@ msgid "%s: Could not set caps\n" msgstr "%s: nepoznat član %s\n" #, fuzzy, c-format -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "nepoznata grupa: %s\n" #, fuzzy, c-format diff --git a/po/ca.po b/po/ca.po index 3678cd260c..7b63c767f0 100644 --- a/po/ca.po +++ b/po/ca.po @@ -234,8 +234,8 @@ msgstr "%s: No s'han pogut establir les «capabilities»\n" #, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" -msgstr "%s: ha fallat stpeprintf!\n" +msgid "%s: seprintf failed!\n" +msgstr "%s: ha fallat seprintf!\n" #, c-format #| msgid "%s: line %d: chown %s failed: %s\n" diff --git a/po/cs.po b/po/cs.po index a720068cd6..776e667d1d 100644 --- a/po/cs.po +++ b/po/cs.po @@ -234,7 +234,7 @@ msgstr "Nelze nastavit jméno uživatele %s\n" #, fuzzy, c-format #| msgid "%s: snprintf failed!\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: snprintf selhalo!\n" #, c-format diff --git a/po/da.po b/po/da.po index fe472aecec..86a775bb51 100644 --- a/po/da.po +++ b/po/da.po @@ -250,7 +250,7 @@ msgstr "Kunne ikke angive navn for %s\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: Linje %d: chown %s fejlede: %s\n" #, fuzzy, c-format diff --git a/po/de.po b/po/de.po index 64a38f756a..01daa98694 100644 --- a/po/de.po +++ b/po/de.po @@ -244,7 +244,7 @@ msgstr "Name für %s konnte nicht gesetzt werden\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: Zeile %d: chown %s (Eigentümer ändern) fehlgeschlagen: %s\n" #, fuzzy, c-format diff --git a/po/dz.po b/po/dz.po index 6c3a3ec7e7..bdc62a2d52 100644 --- a/po/dz.po +++ b/po/dz.po @@ -221,7 +221,7 @@ msgstr "རིམ་སྒྲིག་བརྡ་དོན་གྱི་དོ #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: ཡིག་སྣོད་ཁ་ཕྱེ་མི་ཚུགས།\n" #, fuzzy, c-format diff --git a/po/el.po b/po/el.po index 94d293223b..f708f74b19 100644 --- a/po/el.po +++ b/po/el.po @@ -244,7 +244,7 @@ msgstr "Αδυναμία ρύθμισης του ονόματος χρήστη % #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: αδυναμία ανοίγματος του αρχείου\n" #, fuzzy, c-format diff --git a/po/es.po b/po/es.po index 5336c3317d..616f85f4ac 100644 --- a/po/es.po +++ b/po/es.po @@ -270,7 +270,7 @@ msgstr "No se pudo reservar espacio para la información de configuración.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: no se puede abrir el fichero\n" #, fuzzy, c-format diff --git a/po/eu.po b/po/eu.po index 0c3067e853..9239950390 100644 --- a/po/eu.po +++ b/po/eu.po @@ -227,7 +227,7 @@ msgstr "Ezin izan da lekua esleitu, konfigurazioaren informaziorako.\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: %d lerroa: chown %s-ek huts egin du: %s\n" #, fuzzy, c-format diff --git a/po/fi.po b/po/fi.po index 8dbcddf746..69fcc7a221 100644 --- a/po/fi.po +++ b/po/fi.po @@ -215,7 +215,7 @@ msgstr "Asetustiedoille ei voi varata tilaa.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: tiedosta ei voi avata\n" #, fuzzy, c-format diff --git a/po/fr.po b/po/fr.po index 610a9700e0..143f2ae072 100644 --- a/po/fr.po +++ b/po/fr.po @@ -257,8 +257,8 @@ msgid "%s: Could not set caps\n" msgstr "%s : Impossible de définir les plafonds\n" #, c-format -msgid "%s: stpeprintf failed!\n" -msgstr "%s : échec de stpeprintf !\n" +msgid "%s: seprintf failed!\n" +msgstr "%s : échec de seprintf !\n" #, c-format msgid "%s: open of %s failed: %s\n" diff --git a/po/gl.po b/po/gl.po index 9e3d74a600..71c86b50bb 100644 --- a/po/gl.po +++ b/po/gl.po @@ -217,7 +217,7 @@ msgstr "Non se puido reservar espacio para a información de configuración.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: non se pode abrir o ficheiro\n" #, fuzzy, c-format diff --git a/po/he.po b/po/he.po index fff9d58179..f94bf63aa3 100644 --- a/po/he.po +++ b/po/he.po @@ -211,7 +211,7 @@ msgid "%s: Could not set caps\n" msgstr "לא יכול להקצות מקום בשביל מידע על הקונפיגורציה.\n" #, fuzzy, c-format -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: שורה %d: לא יכול לעדכן רשומת סיסמה\n" #, fuzzy, c-format diff --git a/po/hu.po b/po/hu.po index 628e2301ce..0f73333bff 100644 --- a/po/hu.po +++ b/po/hu.po @@ -212,7 +212,7 @@ msgstr "Sikertelen helyfoglalás a beállítási infónak.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: nem tudom megnyitni a fájlt\n" #, fuzzy, c-format diff --git a/po/id.po b/po/id.po index 2de7dd20c8..0b0eb0a264 100644 --- a/po/id.po +++ b/po/id.po @@ -211,7 +211,7 @@ msgstr "Tidak dapat mengalokasikan ruang untuk informasi konfigurasi.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: tidak dapat membuka berkas\n" #, fuzzy, c-format diff --git a/po/it.po b/po/it.po index 73442e306c..1bd66205dc 100644 --- a/po/it.po +++ b/po/it.po @@ -238,7 +238,7 @@ msgstr "Impossibile allocare spazio per le informazioni di configurazione.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: impossibile aprire il file\n" #, fuzzy, c-format diff --git a/po/ja.po b/po/ja.po index 292c3ca66d..c5c1cc89ec 100644 --- a/po/ja.po +++ b/po/ja.po @@ -237,7 +237,7 @@ msgstr "%s の名前を設定できません\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: %d 行: chown %s が失敗しました: %s\n" #, fuzzy, c-format diff --git a/po/ka.po b/po/ka.po index b5a7a001ff..4f888864d0 100644 --- a/po/ka.po +++ b/po/ka.po @@ -233,8 +233,8 @@ msgid "%s: Could not set caps\n" msgstr "%s: caps-ების დაყენების შედომა\n" #, c-format -msgid "%s: stpeprintf failed!\n" -msgstr "%s: stpeprintf ჩავარდა!\n" +msgid "%s: seprintf failed!\n" +msgstr "%s: seprintf ჩავარდა!\n" #, c-format msgid "%s: open of %s failed: %s\n" diff --git a/po/kk.po b/po/kk.po index ae1caf348b..f0ce4673dd 100644 --- a/po/kk.po +++ b/po/kk.po @@ -235,7 +235,7 @@ msgstr "%s үшін атын орнату мүмкін емес\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: жол %d: chown %s сәтсіз: %s\n" #, fuzzy, c-format diff --git a/po/km.po b/po/km.po index f1381f3d08..060db7cd47 100644 --- a/po/km.po +++ b/po/km.po @@ -225,7 +225,7 @@ msgstr "មិន​អាច​បម្រុង​ទុក​ទំហំ​ #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s ៖ មិន​អាច​បើក​​ឯកសារ​បានទេ\n" #, fuzzy, c-format diff --git a/po/ko.po b/po/ko.po index f15a069307..478a3ac30c 100644 --- a/po/ko.po +++ b/po/ko.po @@ -218,7 +218,7 @@ msgid "%s: Could not set caps\n" msgstr "설정 정보를 위한 공간을 확보할 수 없습니다.\n" #, fuzzy, c-format -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: %d번 줄: chown 실패했습니다\n" #, fuzzy, c-format diff --git a/po/nb.po b/po/nb.po index a922034a5a..9f7016a2c3 100644 --- a/po/nb.po +++ b/po/nb.po @@ -257,7 +257,7 @@ msgstr "Klarte ikke å endre navn på %s\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: klarte ikke å åpne fil\n" #, fuzzy, c-format diff --git a/po/ne.po b/po/ne.po index 64263f4e93..9d3f128827 100644 --- a/po/ne.po +++ b/po/ne.po @@ -218,7 +218,7 @@ msgstr "कनफिगरेसन सूचनाको लागि खाल #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: फाइल खोल्न सकिएन\n" #, fuzzy, c-format diff --git a/po/nl.po b/po/nl.po index 6734cf6dbb..07121c15c8 100644 --- a/po/nl.po +++ b/po/nl.po @@ -232,8 +232,8 @@ msgid "%s: Could not set caps\n" msgstr "%s: Kon hoofdletters niet instellen\n" #, c-format -msgid "%s: stpeprintf failed!\n" -msgstr "%s: stpeprintf is mislukt!\n" +msgid "%s: seprintf failed!\n" +msgstr "%s: seprintf is mislukt!\n" #, c-format msgid "%s: open of %s failed: %s\n" diff --git a/po/nn.po b/po/nn.po index a91e8bcec8..a8301a6fe3 100644 --- a/po/nn.po +++ b/po/nn.po @@ -211,7 +211,7 @@ msgstr "Klarte ikkje finna plass for oppsettsinformasjon.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: klarer ikkje opna fil\n" #, fuzzy, c-format diff --git a/po/pl.po b/po/pl.po index 75744cc898..19036f179a 100644 --- a/po/pl.po +++ b/po/pl.po @@ -222,7 +222,7 @@ msgstr "Nie można przydzielić miejsca dla informacji o konfiguracji.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: nie można otworzyć pliku\n" #, fuzzy, c-format diff --git a/po/pt.po b/po/pt.po index bcd16899dc..be80af1a2b 100644 --- a/po/pt.po +++ b/po/pt.po @@ -249,7 +249,7 @@ msgstr "Não foi possível definir nome para %s\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: linha %d: chown %s falhou: %s\n" #, fuzzy, c-format diff --git a/po/pt_BR.po b/po/pt_BR.po index b8df1930e6..f1e73eb739 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -241,7 +241,7 @@ msgstr "Não foi possível alocar espaço para a informação de configuração. #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s : não foi possível abrir arquivo\n" #, fuzzy, c-format diff --git a/po/ro.po b/po/ro.po index 30045a0be4..a1e254d4d7 100644 --- a/po/ro.po +++ b/po/ro.po @@ -209,8 +209,8 @@ msgid "%s: Could not set caps\n" msgstr "%s: Nu s-au putut defini capacitățile\n" #, c-format -msgid "%s: stpeprintf failed!\n" -msgstr "%s: stpeprintf a eșuat!\n" +msgid "%s: seprintf failed!\n" +msgstr "%s: seprintf a eșuat!\n" #, c-format msgid "%s: open of %s failed: %s\n" diff --git a/po/ru.po b/po/ru.po index 62405a170a..522a8b249f 100644 --- a/po/ru.po +++ b/po/ru.po @@ -250,7 +250,7 @@ msgstr "Невозможно задать имя для %s\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: строка %d: вызов chown %s завершился неудачно: %s\n" #, fuzzy, c-format diff --git a/po/shadow.pot b/po/shadow.pot index 5d3d9feb6b..75b4af5828 100644 --- a/po/shadow.pot +++ b/po/shadow.pot @@ -211,7 +211,7 @@ msgid "%s: Could not set caps\n" msgstr "" #, c-format -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "" #, c-format diff --git a/po/sk.po b/po/sk.po index da910e2076..96d7c3a5f1 100644 --- a/po/sk.po +++ b/po/sk.po @@ -224,7 +224,7 @@ msgstr "Na konfiguračné údaje sa nedá vyhradiť dostatok miesta.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: nedá sa otvoriť súbor\n" #, fuzzy, c-format diff --git a/po/sq.po b/po/sq.po index d62c13aa29..63cb601b60 100644 --- a/po/sq.po +++ b/po/sq.po @@ -212,7 +212,7 @@ msgid "%s: Could not set caps\n" msgstr "Kujdes: grup i panjohur %s\n" #, fuzzy, c-format -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "Kujdes: grup i panjohur %s\n" #, fuzzy, c-format diff --git a/po/sv.po b/po/sv.po index b10c01e95a..937501672d 100644 --- a/po/sv.po +++ b/po/sv.po @@ -237,7 +237,7 @@ msgstr "Kunde inte allokera plats för konfigurationsinformationen.\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: rad %d: chown %s misslyckades: %s\n" #, fuzzy, c-format diff --git a/po/tl.po b/po/tl.po index 87f3bbab5b..f18875bc1d 100644 --- a/po/tl.po +++ b/po/tl.po @@ -225,7 +225,7 @@ msgstr "Hindi makapaglaan ng lugar para sa impormasyong pagsasaayos.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: hindi mabuksan ang talaksan\n" #, fuzzy, c-format diff --git a/po/tr.po b/po/tr.po index a8da88d8a9..511cef6fa4 100644 --- a/po/tr.po +++ b/po/tr.po @@ -217,7 +217,7 @@ msgstr "Yapılandırma bilgileri için yer ayrılamadı.\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: dosya açılamıyor\n" #, fuzzy, c-format diff --git a/po/uk.po b/po/uk.po index 5054eb696b..463fa7ea88 100644 --- a/po/uk.po +++ b/po/uk.po @@ -241,7 +241,7 @@ msgstr "%s: не вдалося встановити можливості\n" #, fuzzy, c-format #| msgid "%s: snprintf failed!\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: помилка snprintf!\n" #, c-format diff --git a/po/vi.po b/po/vi.po index f62bc6be80..35fcc9cafe 100644 --- a/po/vi.po +++ b/po/vi.po @@ -243,7 +243,7 @@ msgstr "Không thể đặt tên %s\n" #, fuzzy, c-format #| msgid "%s: line %d: chown %s failed: %s\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s: dòng %d: lỗi chown (thay đổi quyền sở hữu) %s: %s\n" #, fuzzy, c-format diff --git a/po/zh_CN.po b/po/zh_CN.po index 6dfba8d933..7133be5ff3 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -219,7 +219,7 @@ msgstr "%s:无法设置上限\n" #, fuzzy, c-format #| msgid "%s: snprintf failed!\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s:snprintf 失败\n" #, c-format diff --git a/po/zh_TW.po b/po/zh_TW.po index bd2b5e30fd..1bf47487a6 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -230,7 +230,7 @@ msgstr "無法設定 %s 的名稱\n" #, fuzzy, c-format #| msgid "%s: can't open file\n" -msgid "%s: stpeprintf failed!\n" +msgid "%s: seprintf failed!\n" msgstr "%s:無法打開檔案\n" #, fuzzy, c-format diff --git a/src/chage.c b/src/chage.c index 2563a498d4..cb5675742d 100644 --- a/src/chage.c +++ b/src/chage.c @@ -29,7 +29,7 @@ #include "shadowio.h" #include "shadowlog.h" #include "string/memset/memzero.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/strdup.h" @@ -171,12 +171,12 @@ static int new_fields (void) (void) puts (_("Enter the new value, or press ENTER for the default")); (void) puts (""); - SNPRINTF(buf, "%ld", mindays); + STPRINTF(buf, "%ld", mindays); change_field (buf, sizeof buf, _("Minimum Password Age")); if (a2sl(&mindays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; - SNPRINTF(buf, "%ld", maxdays); + STPRINTF(buf, "%ld", maxdays); change_field (buf, sizeof buf, _("Maximum Password Age")); if (a2sl(&maxdays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; @@ -197,12 +197,12 @@ static int new_fields (void) } } - SNPRINTF(buf, "%ld", warndays); + STPRINTF(buf, "%ld", warndays); change_field (buf, sizeof buf, _("Password Expiration Warning")); if (a2sl(&warndays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; - SNPRINTF(buf, "%ld", inactdays); + STPRINTF(buf, "%ld", inactdays); change_field (buf, sizeof buf, _("Password Inactive")); if (a2sl(&inactdays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; diff --git a/src/chfn.c b/src/chfn.c index acc21a985d..4e05472e25 100644 --- a/src/chfn.c +++ b/src/chfn.c @@ -35,7 +35,7 @@ #include "shadowlog.h" #include "sizeof.h" #include "sssd.h" -#include "string/sprintf/stpeprintf.h" +#include "string/sprintf/seprintf.h" #include "string/strcmp/streq.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/strdup.h" @@ -653,12 +653,12 @@ int main (int argc, char **argv) /* Build the new GECOS field by plastering all the pieces together. */ p = new_gecos; e = new_gecos + countof(new_gecos); - p = stpeprintf(p, e, "%s", fullnm); - p = stpeprintf(p, e, ",%s", roomno); - p = stpeprintf(p, e, ",%s", workph); - p = stpeprintf(p, e, ",%s", homeph); + p = seprintf(p, e, "%s", fullnm); + p = seprintf(p, e, ",%s", roomno); + p = seprintf(p, e, ",%s", workph); + p = seprintf(p, e, ",%s", homeph); if (!streq(slop, "")) - p = stpeprintf(p, e, ",%s", slop); + p = seprintf(p, e, ",%s", slop); if (p == e || p == NULL) { fprintf (stderr, _("%s: fields too long\n"), Prog); diff --git a/src/gpasswd.c b/src/gpasswd.c index 6dec40d662..0dcb9e1fcb 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -36,7 +36,7 @@ #include "shadowlog.h" #include "sssd.h" #include "string/memset/memzero.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/strdup.h" @@ -476,7 +476,7 @@ static void log_gpasswd_failure_group (MAYBE_UNUSED void *arg) { char buf[1024]; - SNPRINTF(buf, " in %s", gr_dbname()); + STPRINTF(buf, " in %s", gr_dbname()); log_gpasswd_failure (buf); } @@ -485,7 +485,7 @@ static void log_gpasswd_failure_gshadow (MAYBE_UNUSED void *arg) { char buf[1024]; - SNPRINTF(buf, " in %s", sgr_dbname()); + STPRINTF(buf, " in %s", sgr_dbname()); log_gpasswd_failure (buf); } #endif /* SHADOWGRP */ @@ -521,7 +521,7 @@ static void log_gpasswd_success (const char *suffix) "password of group %s removed by %s%s", group, myname, suffix)); #ifdef WITH_AUDIT - SNPRINTF(buf, "password of group %s removed by %s%s", + STPRINTF(buf, "password of group %s removed by %s%s", group, myname, suffix); audit_logger_with_group (AUDIT_GRP_CHAUTHTOK, "delete-group-password", @@ -533,7 +533,7 @@ static void log_gpasswd_success (const char *suffix) "access to group %s restricted by %s%s", group, myname, suffix)); #ifdef WITH_AUDIT - SNPRINTF(buf, "access to group %s restricted by %s%s", + STPRINTF(buf, "access to group %s restricted by %s%s", group, myname, suffix); audit_logger_with_group (AUDIT_GRP_MGMT, "restrict-group", @@ -587,7 +587,7 @@ static void log_gpasswd_success_group (MAYBE_UNUSED void *arg) { char buf[1024]; - SNPRINTF(buf, " in %s", gr_dbname()); + STPRINTF(buf, " in %s", gr_dbname()); log_gpasswd_success (buf); } diff --git a/src/groupmod.c b/src/groupmod.c index a508c197fe..2f89d669ed 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -41,7 +41,7 @@ #include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" -#include "string/sprintf/stpeprintf.h" +#include "string/sprintf/seprintf.h" #include "string/strcmp/streq.h" #include "string/strcpy/stpecpy.h" #include "string/strdup/strdup.h" @@ -605,11 +605,11 @@ static void prepare_failure_reports (void) info_passwd.audit_msg = pw; pw_end = pw + 512; - gr = stpeprintf(gr, gr_end, "changing %s; ", gr_dbname ()); + gr = seprintf(gr, gr_end, "changing %s; ", gr_dbname()); #ifdef SHADOWGRP - sgr = stpeprintf(sgr, sgr_end, "changing %s; ", sgr_dbname ()); + sgr = seprintf(sgr, sgr_end, "changing %s; ", sgr_dbname()); #endif - pw = stpeprintf(pw, pw_end, "changing %s; ", pw_dbname ()); + pw = seprintf(pw, pw_end, "changing %s; ", pw_dbname()); info_group.action = gr; #ifdef SHADOWGRP @@ -617,14 +617,11 @@ static void prepare_failure_reports (void) #endif info_passwd.action = pw; - gr = stpeprintf(gr, gr_end, - "group %s/%ju", group_name, (uintmax_t) group_id); + gr = seprintf(gr, gr_end, "group %s/%ju", group_name, (uintmax_t) group_id); #ifdef SHADOWGRP - sgr = stpeprintf(sgr, sgr_end, - "group %s", group_name); + sgr = seprintf(sgr, sgr_end, "group %s", group_name); #endif - pw = stpeprintf(pw, pw_end, - "group %s/%ju", group_name, (uintmax_t) group_id); + pw = seprintf(pw, pw_end, "group %s/%ju", group_name, (uintmax_t) group_id); if (nflg) { gr = stpecpy(gr, gr_end, ", new name: "); @@ -644,10 +641,10 @@ static void prepare_failure_reports (void) } if (gflg) { gr = stpecpy(gr, gr_end, ", new gid: "); - stpeprintf(gr, gr_end, "%ju", (uintmax_t) group_newid); + seprintf(gr, gr_end, "%ju", (uintmax_t) group_newid); pw = stpecpy(pw, pw_end, ", new gid: "); - stpeprintf(pw, pw_end, "%ju", (uintmax_t) group_newid); + seprintf(pw, pw_end, "%ju", (uintmax_t) group_newid); } // FIXME: add a system cleanup diff --git a/src/login.c b/src/login.c index 9f193b0044..3514f8443a 100644 --- a/src/login.c +++ b/src/login.c @@ -40,7 +40,7 @@ #include "shadow/gshadow/endsgent.h" #include "shadowlog.h" #include "string/memset/memzero.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strneq.h" #include "string/strcmp/strprefix.h" @@ -590,16 +590,16 @@ int main (int argc, char **argv) } if (!streq(cp, "")) { - SNPRINTF(fromhost, " on '%.100s' from '%.200s'", tty, cp); + STPRINTF(fromhost, " on '%.100s' from '%.200s'", tty, cp); } else { - SNPRINTF(fromhost, " on '%.100s'", tty); + STPRINTF(fromhost, " on '%.100s'", tty); } free(host); top: /* only allow ALARM sec. for login */ timeout = getdef_unum ("LOGIN_TIMEOUT", ALARM); - SNPRINTF(tmsg, _("\nLogin timed out after %u seconds.\n"), timeout); + STPRINTF(tmsg, _("\nLogin timed out after %u seconds.\n"), timeout); (void) signal (SIGALRM, alarm_handler); if (timeout > 0) { (void) alarm (timeout); @@ -644,7 +644,7 @@ int main (int argc, char **argv) /* Make the login prompt look like we want it */ if (gethostname (hostn, sizeof (hostn)) == 0) { - SNPRINTF(loginprompt, _("%s login: "), hostn); + STPRINTF(loginprompt, _("%s login: "), hostn); } else { STRTCPY(loginprompt, _("login: ")); } diff --git a/src/newgrp.c b/src/newgrp.c index 13b6ac17b4..2ed4f446a8 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -32,7 +32,7 @@ #include "shadow/gshadow/getsgnam.h" #include "shadow/gshadow/sgrp.h" #include "shadowlog.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" #include "string/strdup/strdup.h" @@ -199,7 +199,7 @@ static void check_perms (const struct group *grp, if (streq(grp->gr_passwd, "") || !streq(grp->gr_passwd, cpasswd)) { #ifdef WITH_AUDIT - SNPRINTF(audit_buf, "authentication new_gid=%lu", + STPRINTF(audit_buf, "authentication new_gid=%lu", (unsigned long) grp->gr_gid); audit_logger (AUDIT_GRP_AUTH, audit_buf, NULL, getuid (), SHADOW_AUDIT_FAILURE); @@ -212,7 +212,7 @@ static void check_perms (const struct group *grp, goto failure; } #ifdef WITH_AUDIT - SNPRINTF(audit_buf, "authentication new_gid=%lu", + STPRINTF(audit_buf, "authentication new_gid=%lu", (unsigned long) grp->gr_gid); audit_logger (AUDIT_GRP_AUTH, audit_buf, NULL, getuid (), SHADOW_AUDIT_SUCCESS); @@ -699,7 +699,7 @@ int main (int argc, char **argv) if (setgid (gid) != 0) { perror ("setgid"); #ifdef WITH_AUDIT - SNPRINTF(audit_buf, "changing new_gid=%lu", (unsigned long) gid); + STPRINTF(audit_buf, "changing new_gid=%lu", (unsigned long) gid); audit_logger (AUDIT_CHGRP_ID, audit_buf, NULL, getuid (), SHADOW_AUDIT_FAILURE); #endif @@ -709,7 +709,7 @@ int main (int argc, char **argv) if (setuid (getuid ()) != 0) { perror ("setuid"); #ifdef WITH_AUDIT - SNPRINTF(audit_buf, "changing new_gid=%lu", (unsigned long) gid); + STPRINTF(audit_buf, "changing new_gid=%lu", (unsigned long) gid); audit_logger (AUDIT_CHGRP_ID, audit_buf, NULL, getuid (), SHADOW_AUDIT_FAILURE); #endif @@ -724,7 +724,7 @@ int main (int argc, char **argv) closelog (); execl (SHELL, "sh", "-c", command, (char *) NULL); #ifdef WITH_AUDIT - SNPRINTF(audit_buf, "changing new_gid=%lu", (unsigned long) gid); + STPRINTF(audit_buf, "changing new_gid=%lu", (unsigned long) gid); audit_logger (AUDIT_CHGRP_ID, audit_buf, NULL, getuid (), SHADOW_AUDIT_FAILURE); #endif @@ -792,7 +792,7 @@ int main (int argc, char **argv) } #ifdef WITH_AUDIT - SNPRINTF(audit_buf, "changing new_gid=%lu", (unsigned long) gid); + STPRINTF(audit_buf, "changing new_gid=%lu", (unsigned long) gid); audit_logger (AUDIT_CHGRP_ID, audit_buf, NULL, getuid (), SHADOW_AUDIT_SUCCESS); #endif diff --git a/src/newusers.c b/src/newusers.c index 3f260584d9..8aa7a27fd6 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -55,7 +55,7 @@ #include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strdup/strdup.h" #include "string/strerrno.h" @@ -736,7 +736,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) if (freopen (argv[optind], "r", stdin) == NULL) { char buf[BUFSIZ]; - SNPRINTF(buf, "%s: %s", Prog, argv[1]); + STPRINTF(buf, "%s: %s", Prog, argv[1]); perror (buf); fail_exit (EXIT_FAILURE, !flags->chroot); } diff --git a/src/su.c b/src/su.c index 98ced92a01..6d4510d3d5 100644 --- a/src/su.c +++ b/src/su.c @@ -60,7 +60,7 @@ #include "prototypes.h" #include "shadowlog.h" #include "string/sprintf/aprintf.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" #include "string/strcpy/strtcpy.h" @@ -394,8 +394,8 @@ static void prepare_pam_close_session (void) stderr); (void) kill (-pid_child, caught); - SNPRINTF(kill_msg, _(" ...killed.\n")); - SNPRINTF(wait_msg, _(" ...waiting for child to terminate.\n")); + STPRINTF(kill_msg, _(" ...killed.\n")); + STPRINTF(wait_msg, _(" ...waiting for child to terminate.\n")); /* Any signals other than SIGCHLD and SIGALRM will no longer have any effect, * so it's time to block all of them. */ diff --git a/src/useradd.c b/src/useradd.c index f7e46d6b6d..239f0f377c 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -69,7 +69,7 @@ #include "sssd.h" #include "string/memset/memzero.h" #include "string/sprintf/aprintf.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/strcaseeq.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" @@ -690,7 +690,7 @@ set_defaults(void) /* * Rename the current default file to its backup name. */ - assert(SNPRINTF(buf, "%s-", default_file) != -1); + assert(STPRINTF(buf, "%s-", default_file) != -1); unlink (buf); if ((link (default_file, buf) != 0) && (ENOENT != errno)) { fprintf (stderr, diff --git a/src/vipw.c b/src/vipw.c index 83ff3d92bb..2dfdfc7f30 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -44,7 +44,7 @@ #include "shadowlog.h" #include "sssd.h" #include "string/sprintf/aprintf.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" #include "string/strcmp/streq.h" #include "string/strerrno.h" @@ -206,7 +206,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) /* FIXME: the following should have variable sizes */ char filebackup[1024], fileedit[1024]; - SNPRINTF(filebackup, "%s-", file); + STPRINTF(filebackup, "%s-", file); #ifdef WITH_TCB if (tcb_mode) { if ( (mkdir (TCB_DIR "/" SHADOWTCB_SCRATCHDIR, 0700) != 0) @@ -216,12 +216,12 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) { vipwexit (_("failed to drop privileges"), errno, 1); } - SNPRINTF(fileedit, + STPRINTF(fileedit, TCB_DIR "/" SHADOWTCB_SCRATCHDIR "/.vipw.shadow.%s", user); } else { #endif /* WITH_TCB */ - SNPRINTF(fileedit, "%s.edit", file); + STPRINTF(fileedit, "%s.edit", file); #ifdef WITH_TCB } #endif /* WITH_TCB */ diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 9a6387ebe2..b818851ffd 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -7,7 +7,7 @@ check_PROGRAMS = \ test_adds \ test_atoi_strtoi \ test_chkname \ - test_snprintf \ + test_stprintf \ test_strncpy \ test_strtcpy \ test_typetraits \ @@ -79,16 +79,16 @@ test_logind_LDADD = \ $(LIBSYSTEMD) \ $(NULL) -test_snprintf_SOURCES = \ - ../../lib/string/sprintf/snprintf.c \ - test_snprintf.c \ +test_stprintf_SOURCES = \ + ../../lib/string/sprintf/stprintf.c \ + test_stprintf.c \ $(NULL) -test_snprintf_CFLAGS = \ +test_stprintf_CFLAGS = \ $(AM_CFLAGS) \ $(NULL) -test_snprintf_LDFLAGS = \ +test_stprintf_LDFLAGS = \ $(NULL) -test_snprintf_LDADD = \ +test_stprintf_LDADD = \ $(CMOCKA_LIBS) \ $(NULL) diff --git a/tests/unit/test_snprintf.c b/tests/unit/test_stprintf.c similarity index 60% rename from tests/unit/test_snprintf.c rename to tests/unit/test_stprintf.c index fb22d6d166..4255aeab1d 100644 --- a/tests/unit/test_snprintf.c +++ b/tests/unit/test_stprintf.c @@ -14,19 +14,19 @@ #include #include "sizeof.h" -#include "string/sprintf/snprintf.h" +#include "string/sprintf/stprintf.h" -static void test_SNPRINTF_trunc(void **state); -static void test_SNPRINTF_ok(void **state); +static void test_STPRINTF_trunc(void **state); +static void test_STPRINTF_ok(void **state); int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(test_SNPRINTF_trunc), - cmocka_unit_test(test_SNPRINTF_ok), + cmocka_unit_test(test_STPRINTF_trunc), + cmocka_unit_test(test_STPRINTF_ok), }; return cmocka_run_group_tests(tests, NULL, NULL); @@ -34,33 +34,33 @@ main(void) static void -test_SNPRINTF_trunc(void **state) +test_STPRINTF_trunc(void **state) { char buf[countof("foo")]; // Test that we're not returning SIZE_MAX - assert_true(SNPRINTF(buf, "f%su", "oo") < 0); + assert_true(STPRINTF(buf, "f%su", "oo") < 0); assert_true(strcmp(buf, "foo") == 0); - assert_true(SNPRINTF(buf, "barbaz") == -1); + assert_true(STPRINTF(buf, "barbaz") == -1); assert_true(strcmp(buf, "bar") == 0); } static void -test_SNPRINTF_ok(void **state) +test_STPRINTF_ok(void **state) { char buf[countof("foo")]; - assert_true(SNPRINTF(buf, "%s", "foo") == strlen("foo")); + assert_true(STPRINTF(buf, "%s", "foo") == strlen("foo")); assert_true(strcmp(buf, "foo") == 0); - assert_true(SNPRINTF(buf, "%do", 1) == strlen("1o")); + assert_true(STPRINTF(buf, "%do", 1) == strlen("1o")); assert_true(strcmp(buf, "1o") == 0); - assert_true(SNPRINTF(buf, "f") == strlen("f")); + assert_true(STPRINTF(buf, "f") == strlen("f")); assert_true(strcmp(buf, "f") == 0); - assert_true(SNPRINTF(buf, "") == strlen("")); + assert_true(STPRINTF(buf, "") == strlen("")); assert_true(strcmp(buf, "") == 0); }