Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
6 changes: 3 additions & 3 deletions lib/audit_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions lib/commonio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions lib/get_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/hushed.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/idmapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions lib/pwauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 5 additions & 7 deletions lib/salt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions lib/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <errno.h>
#include "prototypes.h"
#include "defines.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"


extern char **newenvp;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions lib/string/README
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.

Expand Down
17 changes: 17 additions & 0 deletions lib/string/sprintf/seprintf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#include "string/sprintf/seprintf.h"

#include <stdarg.h>


#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
Loading
Loading