Skip to content

Conversation

@alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Jan 1, 2025

Cc: @stoeckmann


Revisions:

v2
  • tfix
$ git range-diff shadow/master gh/asprintf_ asprintf_ 
 1:  cb92c9bf =  1:  cb92c9bf lib/string/sprintf/: [v]aprintf(): Add functions
 2:  565dcd46 =  2:  565dcd46 lib/tcbfuncs.c: Split conditionals
 3:  fa55fb2f !  3:  dc720127 lib/, src/: Use aprintf() instead of asprintf(3)
    @@ lib/tcbfuncs.c: shadowtcb_status shadowtcb_move (/*@NULL@*/const char *user_newn
                return SHADOWTCB_FAILURE;
        }
     -  if (asprintf(&shadow, TCB_FMT, user_newname) == -1) {
    -+  shadow = asprintF_(TCB_FMT, user_newname);
    ++  shadow = aprintf(TCB_FMT, user_newname);
     +  if (shadow == NULL) {
                OUT_OF_MEMORY;
                return SHADOWTCB_FAILURE;
 4:  05f40737 =  4:  20364c16 lib/: Use vaprintf() instead of vasprintf(3)
 5:  910ca5cf =  5:  3f036027 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  840fd9d0 =  6:  c6c5b6f9 lib/, src/: Use xaprintf() instead of xasprintf()
 7:  ee37b595 =  7:  e91543af lib/, src/: Remove unnecessary variables
 8:  5510eb72 =  8:  36f2e2e3 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  339e14ab =  9:  d46909ca lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v2b
  • Rebase
$ git range-diff 4.17.1..gh/asprintf_ master..asprintf_ 
 1:  cb92c9bf =  1:  194632cb lib/string/sprintf/: [v]aprintf(): Add functions
 2:  565dcd46 =  2:  4477dcd2 lib/tcbfuncs.c: Split conditionals
 3:  dc720127 =  3:  1ec6264e lib/, src/: Use aprintf() instead of asprintf(3)
 4:  20364c16 =  4:  75b15ee3 lib/: Use vaprintf() instead of vasprintf(3)
 5:  3f036027 =  5:  183e3e05 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  c6c5b6f9 =  6:  3817fcee lib/, src/: Use xaprintf() instead of xasprintf()
 7:  e91543af =  7:  0f4c4292 lib/, src/: Remove unnecessary variables
 8:  36f2e2e3 =  8:  9ee3c41b lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  d46909ca =  9:  60287718 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v2c
  • Rebase
 1:  194632cb =  1:  5887d521 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  4477dcd2 =  2:  c6a553a4 lib/tcbfuncs.c: Split conditionals
 3:  1ec6264e =  3:  f4222723 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  75b15ee3 =  4:  61bf169d lib/: Use vaprintf() instead of vasprintf(3)
 5:  183e3e05 =  5:  7a27b4e5 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  3817fcee =  6:  199c1d94 lib/, src/: Use xaprintf() instead of xasprintf()
 7:  0f4c4292 =  7:  7544923c lib/, src/: Remove unnecessary variables
 8:  9ee3c41b =  8:  33dee27a lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  60287718 =  9:  f7543211 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v2d
  • Rebase
$ git range-diff master..gh/asprintf_ shadow/master..asprintf_ 
 1:  5887d521 =  1:  aff879b5 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  c6a553a4 =  2:  4bb3fe90 lib/tcbfuncs.c: Split conditionals
 3:  f4222723 =  3:  d44da1a4 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  61bf169d =  4:  082648bd lib/: Use vaprintf() instead of vasprintf(3)
 5:  7a27b4e5 =  5:  8a8e877f lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  199c1d94 !  6:  1e7bb9cb lib/, src/: Use xaprintf() instead of xasprintf()
    @@ lib/Makefile.am: libshadow_la_SOURCES = \
     +  string/sprintf/xaprintf.h \
        string/strchr/strchrcnt.c \
        string/strchr/strchrcnt.h \
    -   string/strchr/stpspn.c \
    +   string/strchr/strchrscnt.c \
     
      ## lib/copydir.c ##
     @@
    @@ src/userdel.c
      #include "string/strcmp/streq.h"
      #include "string/strdup/xstrdup.h"
      
    -@@ src/userdel.c: static int remove_mailbox (void)
    +@@ src/userdel.c: static bool remove_mailbox (void)
        }
      
        if (prefix[0]) {
 7:  7544923c =  7:  801ed4d5 lib/, src/: Remove unnecessary variables
 8:  33dee27a =  8:  a33c76f8 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  f7543211 =  9:  fb328c96 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v2e
  • Rebase
$ git range-diff master..gh/asprintf_ shadow/master..asprintf_ 
 1:  aff879b5 =  1:  3a9bb509 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  4bb3fe90 =  2:  8905808f lib/tcbfuncs.c: Split conditionals
 3:  d44da1a4 =  3:  bff2994b lib/, src/: Use aprintf() instead of asprintf(3)
 4:  082648bd =  4:  aaaa092f lib/: Use vaprintf() instead of vasprintf(3)
 5:  8a8e877f =  5:  9b5bfceb lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  1e7bb9cb =  6:  77cee64b lib/, src/: Use xaprintf() instead of xasprintf()
 7:  801ed4d5 =  7:  0b4a0c0e lib/, src/: Remove unnecessary variables
 8:  a33c76f8 =  8:  bc1885f3 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  fb328c96 =  9:  b76ee5dc lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v2f
  • Rebase
$ git range-diff master..gh/asprintf_ shadow/master..asprintf_ 
 1:  3a9bb509 =  1:  f9904a7a lib/string/sprintf/: [v]aprintf(): Add functions
 2:  8905808f =  2:  94d676f0 lib/tcbfuncs.c: Split conditionals
 3:  bff2994b !  3:  6204313d lib/, src/: Use aprintf() instead of asprintf(3)
    @@ src/useradd.c
     +#include "string/sprintf/aprintf.h"
      #include "string/sprintf/snprintf.h"
      #include "string/sprintf/xasprintf.h"
    - #include "string/strcmp/streq.h"
    + #include "string/strcmp/strcaseeq.h"
     @@ src/useradd.c: get_defaults(void)
        const char  *ccp;
      
 4:  aaaa092f =  4:  52f0783e lib/: Use vaprintf() instead of vasprintf(3)
 5:  9b5bfceb =  5:  828e2f14 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  77cee64b !  6:  be71b233 lib/, src/: Use xaprintf() instead of xasprintf()
    @@ lib/getdef.c
     +#include "string/sprintf/xaprintf.h"
      #include "string/strchr/stpspn.h"
      #include "string/strchr/strrspn.h"
    - #include "string/strcmp/streq.h"
    + #include "string/strcmp/strcaseeq.h"
     @@ lib/getdef.c: void setdef_config_file (const char* file)
      #ifdef USE_ECONF
        char  *cp;
    @@ src/useradd.c
      #include "string/sprintf/snprintf.h"
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
    + #include "string/strcmp/strcaseeq.h"
      #include "string/strcmp/streq.h"
      #include "string/strdup/xstrdup.h"
    - #include "string/strtok/stpsep.h"
     @@ src/useradd.c: get_defaults(void)
                        if (prefix[0]) {
                                char  *dt;
 7:  0b4a0c0e !  7:  c3ca2204 lib/, src/: Remove unnecessary variables
    @@ src/useradd.c: get_defaults(void)
                                def_usrtemplate = xstrdup(ccp);
                        }
     @@ src/useradd.c: static void process_flags (int argc, char **argv)
    -                   exit (E_BAD_ARG);
    +                   exit (E_BAD_NAME);
                }
                if (!dflg) {
     -                  char  *uh;
 8:  bc1885f3 =  8:  eb2c1bf3 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  b76ee5dc =  9:  ca768f28 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3
  • Add comments spelling out the meaning of the letter-soup API names. [@hallyn ]
$ git range-diff master gh/asprintf_ asprintf_ 
 1:  f9904a7a !  1:  28dee096 lib/string/sprintf/: [v]aprintf(): Add functions
    @@ lib/string/sprintf/aprintf.h (new)
     +inline char *vaprintf(const char *restrict fmt, va_list ap);
     +
     +
    ++// allocate print formatted
     +// Like asprintf(3), but simpler; omit the length.
     +inline char *
     +aprintf(const char *restrict fmt, ...)
 2:  94d676f0 =  2:  302f506d lib/tcbfuncs.c: Split conditionals
 3:  6204313d =  3:  e5d2142a lib/, src/: Use aprintf() instead of asprintf(3)
 4:  52f0783e =  4:  8e7201e4 lib/: Use vaprintf() instead of vasprintf(3)
 5:  828e2f14 !  5:  e382f6db lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
    @@ lib/string/sprintf/xaprintf.h (new)
     +inline char *xvaprintf(const char *restrict fmt, va_list ap);
     +
     +
    ++// exit-on-error allocate print formatted
     +inline char *
     +xaprintf(const char *restrict fmt, ...)
     +{
 6:  be71b233 =  6:  2df9b32b lib/, src/: Use xaprintf() instead of xasprintf()
 7:  c3ca2204 =  7:  86149753 lib/, src/: Remove unnecessary variables
 8:  eb2c1bf3 =  8:  bc54adda lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  ca768f28 =  9:  66e9eb5b lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3b
  • Rebase
$ git range-diff master..gh/asprintf_ shadow/master..asprintf_ 
 1:  28dee096 =  1:  ff0e552f lib/string/sprintf/: [v]aprintf(): Add functions
 2:  302f506d =  2:  c9469168 lib/tcbfuncs.c: Split conditionals
 3:  e5d2142a =  3:  f47454fa lib/, src/: Use aprintf() instead of asprintf(3)
 4:  8e7201e4 =  4:  33848ec4 lib/: Use vaprintf() instead of vasprintf(3)
 5:  e382f6db =  5:  3cacf5a2 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  2df9b32b !  6:  3a811a08 lib/, src/: Use xaprintf() instead of xasprintf()
    @@ lib/getdef.c
      #include "shadowlog_internal.h"
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
    - #include "string/strchr/stpspn.h"
    - #include "string/strchr/strrspn.h"
      #include "string/strcmp/strcaseeq.h"
    + #include "string/strcmp/streq.h"
    + #include "string/strspn/stpspn.h"
     @@ lib/getdef.c: void setdef_config_file (const char* file)
      #ifdef USE_ECONF
        char  *cp;
    @@ lib/setupenv.c
      #include "shadowlog.h"
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
    - #include "string/strchr/stpspn.h"
      #include "string/strcmp/streq.h"
      #include "string/strdup/xstrdup.h"
    + #include "string/strspn/stpspn.h"
     @@ lib/setupenv.c: addenv_path(const char *varname, const char *dirname, const char *filename)
      {
        char  *buf;
 7:  86149753 =  7:  0c3db424 lib/, src/: Remove unnecessary variables
 8:  bc54adda =  8:  ecfec672 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  66e9eb5b =  9:  ac143467 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3c
  • Rebase
$ git range-diff master..gh/asprintf_ shadow/master..asprintf_ 
 1:  ff0e552f !  1:  689eb1d6 lib/string/sprintf/: [v]aprintf(): Add functions
    @@ Commit message
     
      ## lib/Makefile.am ##
     @@ lib/Makefile.am: libshadow_la_SOURCES = \
    -   sssd.h \
    +   string/ctype/strisascii/strisdigit.h \
        string/memset/memzero.c \
        string/memset/memzero.h \
     +  string/sprintf/aprintf.c \
 2:  c9469168 =  2:  d511de71 lib/tcbfuncs.c: Split conditionals
 3:  f47454fa =  3:  0edba1e0 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  33848ec4 =  4:  d2cca417 lib/: Use vaprintf() instead of vasprintf(3)
 5:  3cacf5a2 =  5:  42b0e0f0 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  3a811a08 =  6:  debbc05b lib/, src/: Use xaprintf() instead of xasprintf()
 7:  0c3db424 =  7:  ac08cac7 lib/, src/: Remove unnecessary variables
 8:  ecfec672 =  8:  1662a650 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  ac143467 =  9:  932734c4 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3d
  • Rebase
$ git range-diff master..gh/asprintf_ shadow/master..asprintf_ 
 1:  689eb1d6 =  1:  ef3710d8 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  d511de71 =  2:  4877357a lib/tcbfuncs.c: Split conditionals
 3:  0edba1e0 =  3:  7212cb7e lib/, src/: Use aprintf() instead of asprintf(3)
 4:  d2cca417 =  4:  fe5c70f7 lib/: Use vaprintf() instead of vasprintf(3)
 5:  42b0e0f0 !  5:  2aa9e80f lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
    @@ tests/unit/Makefile.am: test_typetraits_LDADD = \
      
     
      ## tests/unit/test_xasprintf.c => tests/unit/test_xaprintf.c ##
    -@@
    --/*
    -- * SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
    -- * SPDX-License-Identifier: BSD-3-Clause
    -- */
    -+// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
    -+// SPDX-License-Identifier: BSD-3-Clause
    - 
    - 
    - #include <setjmp.h>
     @@
      #include <stdint.h>  // Required by <cmocka.h>
      #include <cmocka.h>
    @@ tests/unit/test_xasprintf.c => tests/unit/test_xaprintf.c
     +#include "string/sprintf/xaprintf.h"
      
      
    + #define smock()               _Generic(mock(), uintmax_t: (intmax_t) mock())
      #define assert_unreachable()  assert_true(0)
      
     -#define XASPRINTF_CALLED  (-36)
 6:  debbc05b !  6:  70b87dbc lib/, src/: Use xaprintf() instead of xasprintf()
    @@ src/usermod.c
      #include "string/strdup/xstrdup.h"
      #include "time/day_to_str.h"
     @@ src/usermod.c: static char *new_pw_passwd (char *pw_pass)
    -                         "updating passwd", user_newname, user_newid, 0);
    +                         "updating-passwd", user_newname, user_newid, 1);
      #endif
                SYSLOG ((LOG_INFO, "lock user '%s' password", user_newname));
     -          xasprintf(&buf, "!%s", pw_pass);
 7:  ac08cac7 !  7:  47c5c727 lib/, src/: Remove unnecessary variables
    @@ src/usermod.c: usage (int status)
     -
      #ifdef WITH_AUDIT
                audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
    -                         "updating passwd", user_newname, user_newid, 0);
    +                         "updating-passwd", user_newname, user_newid, 1);
      #endif
                SYSLOG ((LOG_INFO, "lock user '%s' password", user_newname));
     -          buf = xaprintf("!%s", pw_pass);
 8:  1662a650 =  8:  1c39960b lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  932734c4 =  9:  ed62940e lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3e
  • Rebase
$ git range-diff db/master..gh/asprintf_ shadow/master..asprintf_ 
 1:  ef3710d8 =  1:  5121d7b2 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  4877357a =  2:  927b36f1 lib/tcbfuncs.c: Split conditionals
 3:  7212cb7e =  3:  269464a2 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  fe5c70f7 =  4:  2d818976 lib/: Use vaprintf() instead of vasprintf(3)
 5:  2aa9e80f =  5:  06718419 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  70b87dbc =  6:  d0c66ee4 lib/, src/: Use xaprintf() instead of xasprintf()
 7:  47c5c727 =  7:  94442077 lib/, src/: Remove unnecessary variables
 8:  1c39960b =  8:  d5db7a7d lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  ed62940e =  9:  9891beac lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3f
  • Rebase
$ git rd
 1:  5121d7b2 =  1:  c47825d3 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  927b36f1 =  2:  91138c7e lib/tcbfuncs.c: Split conditionals
 3:  269464a2 =  3:  2127bd37 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  2d818976 =  4:  0dcc5b2a lib/: Use vaprintf() instead of vasprintf(3)
 5:  06718419 =  5:  c1dce59a lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  d0c66ee4 =  6:  1c1b60af lib/, src/: Use xaprintf() instead of xasprintf()
 7:  94442077 =  7:  aa7be4dc lib/, src/: Remove unnecessary variables
 8:  d5db7a7d =  8:  b4fa5349 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  9891beac =  9:  5ca167e8 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3g
  • Rebase
$ git rd
 1:  c47825d3 =  1:  dbe3fdb2 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  91138c7e =  2:  450d7fad lib/tcbfuncs.c: Split conditionals
 3:  2127bd37 !  3:  f3fe1e3b lib/, src/: Use aprintf() instead of asprintf(3)
    @@ lib/commonio.c
     +#include "string/sprintf/aprintf.h"
      #include "string/sprintf/snprintf.h"
      #include "string/strcmp/streq.h"
    - #include "string/strtok/stpsep.h"
    + #include "string/strcmp/strprefix.h"
     @@ lib/commonio.c: int commonio_lock_nowait (struct commonio_db *db, bool log)
                return 1;
        }
    @@ lib/copydir.c
     +#include "string/sprintf/aprintf.h"
      #include "string/sprintf/xasprintf.h"
      #include "string/strcmp/streq.h"
    - 
    + #include "string/strcmp/strprefix.h"
     @@ lib/copydir.c: static int copy_tree_impl (const struct path_info *src, const struct path_info *
                        continue;
                }
    @@ src/userdel.c
     +#include "string/sprintf/aprintf.h"
      #include "string/sprintf/xasprintf.h"
      #include "string/strcmp/streq.h"
    - #include "string/strdup/xstrdup.h"
    + #include "string/strcmp/strprefix.h"
     @@ src/userdel.c: static int remove_tcbdir (const char *user_name, uid_t user_id)
                return 0;
        }
 4:  0dcc5b2a =  4:  6d6cf37a lib/: Use vaprintf() instead of vasprintf(3)
 5:  c1dce59a =  5:  373c18b3 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  1c1b60af !  6:  0970c36d lib/, src/: Use xaprintf() instead of xasprintf()
    @@ lib/copydir.c
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/streq.h"
    - 
    + #include "string/strcmp/strprefix.h"
      
     @@ lib/copydir.c: static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c
        lp->ln_dev = sb->st_dev;
    @@ lib/copydir.c: static /*@exposed@*/ /*@null@*/struct link_name *check_link (cons
        links = lp;
      
     @@ lib/copydir.c: static int copy_symlink (const struct path_info *src, const struct path_info *ds
    -   if (strncmp(oldlink, src_orig, strlen(src_orig)) == 0) {
    +   if (strprefix(oldlink, src_orig)) {
                char  *dummy;
      
     -          xasprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig));
    @@ lib/env.c
      #include "string/sprintf/snprintf.h"
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
    + #include "string/strcmp/strprefix.h"
      #include "string/strdup/xstrdup.h"
      
    - 
     @@ lib/env.c: void addenv (const char *string, /*@null@*/const char *value)
        size_t  i, n;
      
    @@ lib/getdef.c
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/strcaseeq.h"
      #include "string/strcmp/streq.h"
    - #include "string/strspn/stpspn.h"
    + #include "string/strcmp/strprefix.h"
     @@ lib/getdef.c: void setdef_config_file (const char* file)
      #ifdef USE_ECONF
        char  *cp;
    @@ lib/prefix_flag.c
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/streq.h"
    - 
    + #include "string/strcmp/strprefix.h"
      
     @@ lib/prefix_flag.c: extern const char* process_prefix_flag (const char* short_opt, int argc, char **
                        exit (E_BAD_ARG);
    @@ lib/setupenv.c
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/streq.h"
    + #include "string/strcmp/strprefix.h"
      #include "string/strdup/xstrdup.h"
    - #include "string/strspn/stpspn.h"
     @@ lib/setupenv.c: addenv_path(const char *varname, const char *dirname, const char *filename)
      {
        char  *buf;
    @@ src/passwd.c
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/streq.h"
    + #include "string/strcmp/strprefix.h"
      #include "string/strcpy/strtcpy.h"
    - #include "string/strdup/xstrdup.h"
     @@ src/passwd.c: static char *update_crypt_pw (char *cp)
        if (lflg && *cp != '!') {
                char  *newpw;
    @@ src/su.c
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/streq.h"
    + #include "string/strcmp/strprefix.h"
      #include "string/strcpy/strtcpy.h"
    - #include "string/strdup/xstrdup.h"
     @@ src/su.c: int main (int argc, char **argv)
                        cp = Basename (shellstr);
                }
    @@ src/useradd.c
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/strcaseeq.h"
      #include "string/strcmp/streq.h"
    - #include "string/strdup/xstrdup.h"
    + #include "string/strcmp/strprefix.h"
     @@ src/useradd.c: get_defaults(void)
                        if (prefix[0]) {
                                char  *dt;
    @@ src/userdel.c
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/streq.h"
    + #include "string/strcmp/strprefix.h"
      #include "string/strdup/xstrdup.h"
    - 
     @@ src/userdel.c: static bool remove_mailbox (void)
        }
      
    @@ src/usermod.c
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/streq.h"
    + #include "string/strcmp/strprefix.h"
      #include "string/strdup/xstrdup.h"
    - #include "time/day_to_str.h"
     @@ src/usermod.c: static char *new_pw_passwd (char *pw_pass)
                              "updating-passwd", user_newname, user_newid, 1);
      #endif
    @@ src/usermod.c: static char *new_pw_passwd (char *pw_pass)
     -          xasprintf(&buf, "!%s", pw_pass);
     +          buf = xaprintf("!%s", pw_pass);
                pw_pass = buf;
    -   } else if (Uflg && pw_pass[0] == '!') {
    +   } else if (Uflg && strprefix(pw_pass, "!")) {
                if (pw_pass[1] == '\0') {
     @@ src/usermod.c: process_flags(int argc, char **argv)
                user_newgid = user_gid;
 7:  aa7be4dc !  7:  7c1aac2c lib/, src/: Remove unnecessary variables
    @@ src/usermod.c: usage (int status)
     -          buf = xaprintf("!%s", pw_pass);
     -          pw_pass = buf;
     +          pw_pass = xaprintf("!%s", pw_pass);
    -   } else if (Uflg && pw_pass[0] == '!') {
    +   } else if (Uflg && strprefix(pw_pass, "!")) {
                if (pw_pass[1] == '\0') {
                        fprintf (stderr,
 8:  b4fa5349 =  8:  3ac2633e lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  5ca167e8 =  9:  e3703f7f lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3h
  • Rebase
$ git rd
 1:  dbe3fdb2 =  1:  a06fae29 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  450d7fad =  2:  e8979d5c lib/tcbfuncs.c: Split conditionals
 3:  f3fe1e3b =  3:  74a08615 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  6d6cf37a =  4:  fb08ca68 lib/: Use vaprintf() instead of vasprintf(3)
 5:  373c18b3 =  5:  274d9ac6 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  0970c36d =  6:  63c13454 lib/, src/: Use xaprintf() instead of xasprintf()
 7:  7c1aac2c =  7:  65ec0f15 lib/, src/: Remove unnecessary variables
 8:  3ac2633e =  8:  818afaec lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  e3703f7f =  9:  750d34bc lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3i
  • Rebase
$ git rd 
 1:  a06fae29 !  1:  b21fffcc lib/string/sprintf/: [v]aprintf(): Add functions
    @@ Commit message
     
      ## lib/Makefile.am ##
     @@ lib/Makefile.am: libshadow_la_SOURCES = \
    -   string/ctype/strisascii/strisdigit.h \
    +   string/ctype/strtoascii/strtolower.h \
        string/memset/memzero.c \
        string/memset/memzero.h \
     +  string/sprintf/aprintf.c \
 2:  e8979d5c =  2:  fc6863e3 lib/tcbfuncs.c: Split conditionals
 3:  74a08615 =  3:  d6436642 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  fb08ca68 =  4:  93eb640f lib/: Use vaprintf() instead of vasprintf(3)
 5:  274d9ac6 =  5:  1135af25 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  63c13454 !  6:  fd73330a lib/, src/: Use xaprintf() instead of xasprintf()
    @@ lib/mail.c: void mailcheck (void)
     
      ## lib/obscure.c ##
     @@
    - #include "defines.h"
      #include "getdef.h"
    + #include "string/ctype/strtoascii/strtolower.h"
      #include "string/memset/memzero.h"
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
    @@ lib/obscure.c
      
     @@ lib/obscure.c: static /*@observer@*//*@null@*/const char *password_check (
      
    -   newmono = str_lower (xstrdup (new));
    -   oldmono = str_lower (xstrdup (old));
    +   newmono = strtolower(xstrdup(new));
    +   oldmono = strtolower(xstrdup(old));
     -  xasprintf(&wrapped, "%s%s", oldmono, oldmono);
     +  wrapped = xaprintf("%s%s", oldmono, oldmono);
      
 7:  65ec0f15 =  7:  4f935ba6 lib/, src/: Remove unnecessary variables
 8:  818afaec =  8:  7b9b8ac4 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  750d34bc =  9:  0d67f965 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3j
  • Rebase
$ git rd
 1:  b21fffcc =  1:  900a0ba0 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  fc6863e3 =  2:  999757c5 lib/tcbfuncs.c: Split conditionals
 3:  d6436642 =  3:  fc2db923 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  93eb640f =  4:  63f71e0d lib/: Use vaprintf() instead of vasprintf(3)
 5:  1135af25 =  5:  bb986179 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  fd73330a =  6:  987db1a8 lib/, src/: Use xaprintf() instead of xasprintf()
 7:  4f935ba6 =  7:  f32bee0f lib/, src/: Remove unnecessary variables
 8:  7b9b8ac4 =  8:  1a806c29 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  0d67f965 =  9:  86a4282a lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3k
  • Rebase
$ git rd 
 1:  900a0ba0 =  1:  ec8988ef lib/string/sprintf/: [v]aprintf(): Add functions
 2:  999757c5 =  2:  fe459584 lib/tcbfuncs.c: Split conditionals
 3:  fc2db923 =  3:  4d97c686 lib/, src/: Use aprintf() instead of asprintf(3)
 4:  63f71e0d =  4:  8d733ed2 lib/: Use vaprintf() instead of vasprintf(3)
 5:  bb986179 =  5:  ee5cd37d lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  987db1a8 =  6:  08ee583b lib/, src/: Use xaprintf() instead of xasprintf()
 7:  f32bee0f =  7:  8bb475c9 lib/, src/: Remove unnecessary variables
 8:  1a806c29 =  8:  1d3f5225 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  86a4282a =  9:  742660ab lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v3l
  • Rebase
$ git rd
 1:  ec8988ef =  1:  ab1fbbb8 lib/string/sprintf/: [v]aprintf(): Add functions
 2:  fe459584 =  2:  1edf26b3 lib/tcbfuncs.c: Split conditionals
 3:  4d97c686 =  3:  d2b1c25f lib/, src/: Use aprintf() instead of asprintf(3)
 4:  8d733ed2 =  4:  ce42c005 lib/: Use vaprintf() instead of vasprintf(3)
 5:  ee5cd37d =  5:  dcfabb01 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  08ee583b !  6:  5e69fefb lib/, src/: Use xaprintf() instead of xasprintf()
    @@ lib/env.c: void addenv (const char *string, /*@null@*/const char *value)
     
      ## lib/getdef.c ##
     @@
    - #include "getdef.h"
      #include "prototypes.h"
      #include "shadowlog_internal.h"
    + #include "sizeof.h"
     -#include "string/sprintf/xasprintf.h"
     +#include "string/sprintf/xaprintf.h"
      #include "string/strcmp/strcaseeq.h"
 7:  8bb475c9 =  7:  5292fd44 lib/, src/: Remove unnecessary variables
 8:  1d3f5225 =  8:  75d0ff94 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  742660ab =  9:  27938702 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling

@alejandro-colomar alejandro-colomar changed the title [x][v]asprintf_(): Add APIs, and use them [x][v]asprintf_(): Add APIs, and use them instead of [x][v]asprintf(3) Jan 1, 2025
@alejandro-colomar alejandro-colomar force-pushed the asprintf_ branch 7 times, most recently from 8426bbd to aaa727a Compare January 1, 2025 15:58
@alejandro-colomar alejandro-colomar marked this pull request as ready for review January 1, 2025 16:49
@alejandro-colomar alejandro-colomar changed the title [x][v]asprintf_(): Add APIs, and use them instead of [x][v]asprintf(3) [x][v]aprintf(): Add APIs, and use them instead of [x][v]asprintf(3) Jan 2, 2025
@alejandro-colomar alejandro-colomar force-pushed the asprintf_ branch 2 times, most recently from d8ac495 to 75c5f3f Compare January 2, 2025 02:22
@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Jan 2, 2025

As a curiosity, this aprintf() API seems to be exactly the same that Plan9 calls smprint(3).

https://9fans.github.io/plan9port/man/man3/print.html

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented May 5, 2025

This API has been discussed in the C Committee for inclusion in C2y, and there seems to be interest in the API. Here's a draft of a proposal, which will probably be voted in the next committee meeting (2025-08): https://www.alejandro-colomar.es/src/alx/alx/wg14/alx-0007.git/tree/alx-0007.txt.

@alejandro-colomar alejandro-colomar force-pushed the asprintf_ branch 3 times, most recently from 750d34b to 0d67f96 Compare May 31, 2025 00:10
@alejandro-colomar
Copy link
Collaborator Author

@hallyn Thanks for your time and work reviewing and merging stuff! I've finished rebasing everything of mine after the recent merges, so feel free to continue reviewing and merging. :)

@alejandro-colomar alejandro-colomar force-pushed the asprintf_ branch 2 times, most recently from 86a4282 to 742660a Compare June 3, 2025 08:00
These functions are just like [v]asprintf(3), but simpler.

They return the newly allocated memory, which allows us to use the
[[gnu::malloc(free)]] attribute, which enhances static analysis.
They also omit the length, which we don't care about at all.

As a curiosity, Plan9 seems to provide this same API, under the name
smprint(3).

Link: <https://9fans.github.io/plan9port/man/man3/print.html>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This is in preparation for the next commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
…printf()

Wrap [v]aprintf() instead of [v]asprintf(3).

Repurpose x[v]asprintf()'s tests to test x[v]aprintf().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This makes some temporary variables unnecessary.  They'll be removed in
the next commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
…ttern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
All these 3 branches have a compatible return value, which we can check
at once after the branches.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
@hallyn hallyn merged commit b9323a0 into shadow-maint:master Jun 4, 2025
10 checks passed
@alejandro-colomar alejandro-colomar deleted the asprintf_ branch June 4, 2025 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants