Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uh, get some more numbers #899

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Jan 11, 2024


v3 v3 changes:
  • Rebase
$ git range-diff gh/strtoll..gh/getuh strtoll..getuh 
 1:  806f0ff5 =  1:  81c8665d lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
 2:  f0181f03 =  2:  edff0c98 lib/getdef.c: getdef_unum(): Fix wrong limit check
 3:  6d9d10eb =  3:  fd6cfab8 lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
 4:  f4692dc4 =  4:  435aa712 lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
 5:  36614d26 =  5:  e4b220b9 lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 6:  b9dcbb2b =  6:  14c14376 lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
 7:  9df29b9f =  7:  1e642aef lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
 8:  d0f99086 =  8:  c214e9fd lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 9:  e143fb48 =  9:  bf67cb06 lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
10:  402bec05 = 10:  9d802247 lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
11:  a88d11a7 = 11:  9ba02c4b lib/shadow.c: my_sgetspent(): Remove dead code
12:  2af1a7bf = 12:  047becc1 lib/shadow.c: my_sgetspent(): Simplify error handling
13:  aff746c6 = 13:  486488d9 src/check_subid_range.c: Call get_uid() instead of str2sl()
14:  dbe51a22 = 14:  49058180 src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
15:  5359d519 = 15:  364e750b src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
16:  321774db = 16:  6e4e8d11 src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
17:  48461308 = 17:  eaa538b6 src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
18:  38704923 = 18:  395b5cdd src/chage.c: Simplify, by calling a2sl() instead of str2sl()
v4 v4 changes:
  • Rebase
$ git range-diff 81c8665d^..gh/getuh strtoll..getuh 
 1:  81c8665d =  1:  3b304bae lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
 2:  edff0c98 =  2:  ff6f6f54 lib/getdef.c: getdef_unum(): Fix wrong limit check
 3:  fd6cfab8 =  3:  943653e5 lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
 4:  435aa712 =  4:  a72137c8 lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
 5:  e4b220b9 =  5:  33bd3e2d lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 6:  14c14376 =  6:  8fc11068 lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
 7:  1e642aef =  7:  44e1c015 lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
 8:  c214e9fd =  8:  215349f5 lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 9:  bf67cb06 =  9:  f0b9183c lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
10:  9d802247 = 10:  694cc6b6 lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
11:  9ba02c4b = 11:  903b7549 lib/shadow.c: my_sgetspent(): Remove dead code
12:  047becc1 = 12:  7add9a04 lib/shadow.c: my_sgetspent(): Simplify error handling
13:  486488d9 = 13:  5375dd9a src/check_subid_range.c: Call get_uid() instead of str2sl()
14:  49058180 = 14:  08995a95 src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
15:  364e750b = 15:  26ee8c71 src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
16:  6e4e8d11 = 16:  28f4241e src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
17:  eaa538b6 = 17:  3633d2fb src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
18:  395b5cdd = 18:  8a475e05 src/chage.c: Simplify, by calling a2sl() instead of str2sl()

@alejandro-colomar
Copy link
Collaborator Author

v2 changes:

  • Rebase to master
$ git range-diff --creation-factor=99 gh/strtoll..gh/getuh strtoll..getuh 
 1:  8d7d5b18 =  1:  ca06c536 lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
 2:  739856c5 =  2:  f39d39b5 lib/getdef.c: getdef_unum(): Fix wrong limit check
 3:  810acd36 =  3:  dc98f63e lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
 4:  096eede0 =  4:  c9d86e9e lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
 5:  ab2d2fdd =  5:  1ab4608d lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 6:  63902a40 =  6:  93439f65 lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
 7:  aa66f0cd =  7:  6d1b9361 lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
 8:  b06780b6 =  8:  d79de598 lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 9:  ef712a6b !  9:  db9121fe lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
    @@ Commit message
     
      ## lib/sgetspent.c ##
     @@
    - #include "defines.h"
    - #include <stdio.h>
    + #include <sys/types.h>
    + #include <string.h>
      
     +#include "atoi/a2i.h"
      #include "atoi/str2i.h"
    - 
    - 
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    + #include "prototypes.h"
    + #include "shadowlog_internal.h"
    +@@ lib/sgetspent.c: sgetspent(const char *string)
         * incorrectly formatted number.
         */
      
    @@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
     -  } else if (   (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
     -             || (spwd.sp_lstchg < 0)) {
     +  else if (a2sl(&spwd.sp_lstchg, fields[2], NULL, 0, 0, LONG_MAX) == -1)
    -           return 0;
    +           return NULL;
     -  }
      
        /*
    @@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
     -  } else if (   (str2sl(&spwd.sp_min, fields[3]) == -1)
     -             || (spwd.sp_min < 0)) {
     +  else if (a2sl(&spwd.sp_min, fields[3], NULL, 0, 0, LONG_MAX) == -1)
    -           return 0;
    +           return NULL;
     -  }
      
        /*
    @@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
     -  } else if (   (str2sl(&spwd.sp_max, fields[4]) == -1)
     -             || (spwd.sp_max < 0)) {
     +  else if (a2sl(&spwd.sp_max, fields[4], NULL, 0, 0, LONG_MAX) == -1)
    -           return 0;
    +           return NULL;
     -  }
      
        /*
         * If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    +@@ lib/sgetspent.c: sgetspent(const char *string)
         * Get the number of days of password expiry warning.
         */
      
    @@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
     -  } else if (   (str2sl(&spwd.sp_warn, fields[5]) == -1)
     -             || (spwd.sp_warn < 0)) {
     +  else if (a2sl(&spwd.sp_warn, fields[5], NULL, 0, 0, LONG_MAX) == -1)
    -           return 0;
    +           return NULL;
     -  }
      
        /*
    @@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
     -  } else if (   (str2sl(&spwd.sp_inact, fields[6]) == -1)
     -             || (spwd.sp_inact < 0)) {
     +  else if (a2sl(&spwd.sp_inact, fields[6], NULL, 0, 0, LONG_MAX) == -1)
    -           return 0;
    +           return NULL;
     -  }
      
        /*
    @@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
     -  } else if (   (str2sl(&spwd.sp_expire, fields[7]) == -1)
     -             || (spwd.sp_expire < 0)) {
     +  else if (a2sl(&spwd.sp_expire, fields[7], NULL, 0, 0, LONG_MAX) == -1)
    -           return 0;
    +           return NULL;
     -  }
      
        /*
    @@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
                spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
     -  } else if (str2ul(&spwd.sp_flag, fields[8]) == -1) {
     +  else if (str2ul(&spwd.sp_flag, fields[8]) == -1)
    -           return 0;
    +           return NULL;
     -  }
      
        return (&spwd);
10:  c6da9e43 ! 10:  b01a0529 lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
    @@ Commit message
     
      ## lib/shadow.c ##
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    +    * incorrectly formatted number, unless we are using NIS.
    +    */
      
    -   if (fields[2][0] == '\0') {
    +-  if (fields[2][0] == '\0') {
    ++  if (fields[2][0] == '\0')
                spwd.sp_lstchg = -1;
     -  } else {
    --          if (str2sl(&spwd.sp_lstchg, fields[2]) == -1) {
    -+  } else if (str2sl(&spwd.sp_lstchg, fields[2]) == -1) {
    - #ifdef    USE_NIS
    --                  if (nis_used) {
    --                          spwd.sp_lstchg = -1;
    --                  } else
    -+          if (nis_used) {
    -+                  spwd.sp_lstchg = -1;
    -+          } else
    - #endif
    --                          return 0;
    --          } else if (spwd.sp_lstchg < 0) {
    -+          {
    -                   return 0;
    -           }
    -+  } else if (spwd.sp_lstchg < 0) {
    +-          if (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
    +-                  return 0;
    +-          if (spwd.sp_lstchg < 0)
    +-                  return 0;
    +-  }
    ++  else if (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
    ++          return 0;
    ++  else if (spwd.sp_lstchg < 0)
     +          return 0;
    -   }
      
        /*
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    +    * Get the minimum period between password changes.
    +    */
      
    -   if (fields[3][0] == '\0') {
    +-  if (fields[3][0] == '\0') {
    ++  if (fields[3][0] == '\0')
                spwd.sp_min = -1;
     -  } else {
    --          if (str2sl(&spwd.sp_min, fields[3]) == -1) {
    -+  } else if (str2sl(&spwd.sp_min, fields[3]) == -1) {
    - #ifdef    USE_NIS
    --                  if (nis_used) {
    --                          spwd.sp_min = -1;
    --                  } else
    -+          if (nis_used) {
    -+                  spwd.sp_min = -1;
    -+          } else
    - #endif
    --                  {
    --                          return 0;
    --                  }
    --          } else if (spwd.sp_min < 0) {
    -+          {
    -                   return 0;
    -           }
    -+  } else if (spwd.sp_min < 0) {
    +-          if (str2sl(&spwd.sp_min, fields[3]) == -1)
    +-                  return 0;
    +-          if (spwd.sp_min < 0)
    +-                  return 0;
    +-  }
    ++  else if (str2sl(&spwd.sp_min, fields[3]) == -1)
    ++          return 0;
    ++  else if (spwd.sp_min < 0)
     +          return 0;
    -   }
      
        /*
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    +    * Get the maximum number of days a password is valid.
    +    */
      
    -   if (fields[4][0] == '\0') {
    +-  if (fields[4][0] == '\0') {
    ++  if (fields[4][0] == '\0')
                spwd.sp_max = -1;
     -  } else {
    --          if (str2sl(&spwd.sp_max, fields[4]) == -1) {
    -+  } else if (str2sl(&spwd.sp_max, fields[4]) == -1) {
    - #ifdef    USE_NIS
    --                  if (nis_used) {
    --                          spwd.sp_max = -1;
    --                  } else
    -+          if (nis_used) {
    -+                  spwd.sp_max = -1;
    -+          } else
    - #endif
    --                          return 0;
    --          } else if (spwd.sp_max < 0) {
    -+          {
    -                   return 0;
    -           }
    -+  } else if (spwd.sp_max < 0) {
    +-          if (str2sl(&spwd.sp_max, fields[4]) == -1)
    +-                  return 0;
    +-          if (spwd.sp_max < 0)
    +-                  return 0;
    +-  }
    ++  else if (str2sl(&spwd.sp_max, fields[4]) == -1)
    ++          return 0;
    ++  else if (spwd.sp_max < 0)
     +          return 0;
    -   }
      
        /*
    +    * If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    +    * Get the number of days of password expiry warning.
    +    */
      
    -   if (fields[5][0] == '\0') {
    +-  if (fields[5][0] == '\0') {
    ++  if (fields[5][0] == '\0')
                spwd.sp_warn = -1;
     -  } else {
    --          if (str2sl(&spwd.sp_warn, fields[5]) == -1) {
    -+  } else if (str2sl(&spwd.sp_warn, fields[5]) == -1) {
    - #ifdef    USE_NIS
    --                  if (nis_used) {
    --                          spwd.sp_warn = -1;
    --                  } else
    -+          if (nis_used) {
    -+                  spwd.sp_warn = -1;
    -+          } else
    - #endif
    --                  {
    --                          return 0;
    --                  }
    --          } else if (spwd.sp_warn < 0) {
    -+          {
    -                   return 0;
    -           }
    -+  } else if (spwd.sp_warn < 0) {
    +-          if (str2sl(&spwd.sp_warn, fields[5]) == -1)
    +-                  return 0;
    +-          if (spwd.sp_warn < 0)
    +-                  return 0;
    +-  }
    ++  else if (str2sl(&spwd.sp_warn, fields[5]) == -1)
    ++          return 0;
    ++  else if (spwd.sp_warn < 0)
     +          return 0;
    -   }
      
        /*
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    +    * Get the number of days of inactivity before an account is
    +    * disabled.
    +    */
      
    -   if (fields[6][0] == '\0') {
    +-  if (fields[6][0] == '\0') {
    ++  if (fields[6][0] == '\0')
                spwd.sp_inact = -1;
     -  } else {
    --          if (str2sl(&spwd.sp_inact, fields[6]) == -1) {
    -+  } else if (str2sl(&spwd.sp_inact, fields[6]) == -1) {
    - #ifdef    USE_NIS
    --                  if (nis_used) {
    --                          spwd.sp_inact = -1;
    --                  } else
    -+          if (nis_used) {
    -+                  spwd.sp_inact = -1;
    -+          } else
    - #endif
    --                  {
    --                          return 0;
    --                  }
    --          } else if (spwd.sp_inact < 0) {
    -+          {
    -                   return 0;
    -           }
    -+  } else if (spwd.sp_inact < 0) {
    +-          if (str2sl(&spwd.sp_inact, fields[6]) == -1)
    +-                  return 0;
    +-          if (spwd.sp_inact < 0)
    +-                  return 0;
    +-  }
    ++  else if (str2sl(&spwd.sp_inact, fields[6]) == -1)
    ++          return 0;
    ++  else if (spwd.sp_inact < 0)
     +          return 0;
    -   }
      
        /*
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    +    * Get the number of days after the epoch before the account is
    +    * set to expire.
    +    */
      
    -   if (fields[7][0] == '\0') {
    +-  if (fields[7][0] == '\0') {
    ++  if (fields[7][0] == '\0')
                spwd.sp_expire = -1;
     -  } else {
    --          if (str2sl(&spwd.sp_expire, fields[7]) == -1) {
    -+  } else if (str2sl(&spwd.sp_expire, fields[7]) == -1) {
    - #ifdef    USE_NIS
    --                  if (nis_used) {
    --                          spwd.sp_expire = -1;
    --                  } else
    -+          if (nis_used) {
    -+                  spwd.sp_expire = -1;
    -+          } else
    - #endif
    --                  {
    --                          return 0;
    --                  }
    --          } else if (spwd.sp_expire < 0) {
    -+          {
    -                   return 0;
    -           }
    -+  } else if (spwd.sp_expire < 0) {
    +-          if (str2sl(&spwd.sp_expire, fields[7]) == -1)
    +-                  return 0;
    +-          if (spwd.sp_expire < 0)
    +-                  return 0;
    +-  }
    ++  else if (str2sl(&spwd.sp_expire, fields[7]) == -1)
    ++          return 0;
    ++  else if (spwd.sp_expire < 0)
     +          return 0;
    -   }
      
        /*
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    +    * This field is reserved for future use.  But it isn't supposed
    +    * to have anything other than a valid integer in it.
    +    */
      
    -   if (fields[8][0] == '\0') {
    +-  if (fields[8][0] == '\0') {
    ++  if (fields[8][0] == '\0')
                spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
     -  } else {
    --          if (str2ul(&spwd.sp_flag, fields[8]) == -1) {
    -+  } else if (str2ul(&spwd.sp_flag, fields[8]) == -1) {
    - #ifdef    USE_NIS
    --                  if (nis_used) {
    --                          spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
    --                  } else
    -+          if (nis_used) {
    -+                  spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
    -+          } else
    - #endif
    --                  {
    --                          return 0;
    --                  }
    --          } else if (spwd.sp_flag < 0) {
    -+          {
    -                   return 0;
    -           }
    -+  } else if (spwd.sp_flag < 0) {
    +-          if (str2ul(&spwd.sp_flag, fields[8]) == -1)
    +-                  return 0;
    +-          if (spwd.sp_flag < 0)
    +-                  return 0;
    +-  }
    ++  else if (str2ul(&spwd.sp_flag, fields[8]) == -1)
    ++          return 0;
    ++  else if (spwd.sp_flag < 0)
     +          return 0;
    -   }
      
        return (&spwd);
    + }
11:  ba5da730 ! 11:  0e1edd82 lib/shadow.c: my_sgetspent(): Remove dead code
    @@ Commit message
     
      ## lib/shadow.c ##
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    -           {
    -                   return 0;
    -           }
    --  } else if (spwd.sp_flag < 0) {
    +           spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
    +   else if (str2ul(&spwd.sp_flag, fields[8]) == -1)
    +           return 0;
    +-  else if (spwd.sp_flag < 0)
     -          return 0;
    -   }
      
        return (&spwd);
    + }
12:  37aa0119 ! 12:  56f18e94 lib/shadow.c: my_sgetspent(): Fix error handling
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/shadow.c: my_sgetspent(): Fix error handling
    -
    -    If "negative seven" is not an error if USE_NIS, I don't think "-7"
    -    should be either.
    +    lib/shadow.c: my_sgetspent(): Simplify error handling
     
         Handle negative values as errors from a2sl(), and reuse its
         error-handling code.
     
    -    Fixes: 9a7f5c6b16ef ("* lib/shadow.c: Replace strtol() by getlong(). Also detect more issues in a numerical shadow entry field.")
    -    Link: <https://github.com/shadow-maint/shadow/commit/9a7f5c6b16ef9d1ca8637a3dcb5e27cd1c5dc372>
         Cc: Iker Pedrosa <ipedrosa@redhat.com>
         Cc: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
    @@ lib/shadow.c
      
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
      
    -   if (fields[2][0] == '\0') {
    +   if (fields[2][0] == '\0')
                spwd.sp_lstchg = -1;
    --  } else if (str2sl(&spwd.sp_lstchg, fields[2]) == -1) {
    -+  } else if (a2sl(&spwd.sp_lstchg, fields[2], NULL, 0, 0, LONG_MAX) == -1) {
    - #ifdef    USE_NIS
    -           if (nis_used) {
    -                   spwd.sp_lstchg = -1;
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    -           {
    -                   return 0;
    -           }
    --  } else if (spwd.sp_lstchg < 0) {
    +-  else if (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
     -          return 0;
    -   }
    +-  else if (spwd.sp_lstchg < 0)
    ++  else if (a2sl(&spwd.sp_lstchg, fields[2], NULL, 0, 0, LONG_MAX) == -1)
    +           return 0;
      
        /*
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
      
    -   if (fields[3][0] == '\0') {
    +   if (fields[3][0] == '\0')
                spwd.sp_min = -1;
    --  } else if (str2sl(&spwd.sp_min, fields[3]) == -1) {
    -+  } else if (a2sl(&spwd.sp_min, fields[3], NULL, 0, 0, LONG_MAX) == -1) {
    - #ifdef    USE_NIS
    -           if (nis_used) {
    -                   spwd.sp_min = -1;
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    -           {
    -                   return 0;
    -           }
    --  } else if (spwd.sp_min < 0) {
    +-  else if (str2sl(&spwd.sp_min, fields[3]) == -1)
     -          return 0;
    -   }
    +-  else if (spwd.sp_min < 0)
    ++  else if (a2sl(&spwd.sp_min, fields[3], NULL, 0, 0, LONG_MAX) == -1)
    +           return 0;
      
        /*
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
      
    -   if (fields[4][0] == '\0') {
    +   if (fields[4][0] == '\0')
                spwd.sp_max = -1;
    --  } else if (str2sl(&spwd.sp_max, fields[4]) == -1) {
    -+  } else if (a2sl(&spwd.sp_max, fields[4], NULL, 0, 0, LONG_MAX) == -1) {
    - #ifdef    USE_NIS
    -           if (nis_used) {
    -                   spwd.sp_max = -1;
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    -           {
    -                   return 0;
    -           }
    --  } else if (spwd.sp_max < 0) {
    +-  else if (str2sl(&spwd.sp_max, fields[4]) == -1)
     -          return 0;
    -   }
    +-  else if (spwd.sp_max < 0)
    ++  else if (a2sl(&spwd.sp_max, fields[4], NULL, 0, 0, LONG_MAX) == -1)
    +           return 0;
      
        /*
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
      
    -   if (fields[5][0] == '\0') {
    +   if (fields[5][0] == '\0')
                spwd.sp_warn = -1;
    --  } else if (str2sl(&spwd.sp_warn, fields[5]) == -1) {
    -+  } else if (a2sl(&spwd.sp_warn, fields[5], NULL, 0, 0, LONG_MAX) == -1) {
    - #ifdef    USE_NIS
    -           if (nis_used) {
    -                   spwd.sp_warn = -1;
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    -           {
    -                   return 0;
    -           }
    --  } else if (spwd.sp_warn < 0) {
    +-  else if (str2sl(&spwd.sp_warn, fields[5]) == -1)
     -          return 0;
    -   }
    +-  else if (spwd.sp_warn < 0)
    ++  else if (a2sl(&spwd.sp_warn, fields[5], NULL, 0, 0, LONG_MAX) == -1)
    +           return 0;
      
        /*
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
      
    -   if (fields[6][0] == '\0') {
    +   if (fields[6][0] == '\0')
                spwd.sp_inact = -1;
    --  } else if (str2sl(&spwd.sp_inact, fields[6]) == -1) {
    -+  } else if (a2sl(&spwd.sp_inact, fields[6], NULL, 0, 0, LONG_MAX) == -1) {
    - #ifdef    USE_NIS
    -           if (nis_used) {
    -                   spwd.sp_inact = -1;
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    -           {
    -                   return 0;
    -           }
    --  } else if (spwd.sp_inact < 0) {
    +-  else if (str2sl(&spwd.sp_inact, fields[6]) == -1)
     -          return 0;
    -   }
    +-  else if (spwd.sp_inact < 0)
    ++  else if (a2sl(&spwd.sp_inact, fields[6], NULL, 0, 0, LONG_MAX) == -1)
    +           return 0;
      
        /*
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
      
    -   if (fields[7][0] == '\0') {
    +   if (fields[7][0] == '\0')
                spwd.sp_expire = -1;
    --  } else if (str2sl(&spwd.sp_expire, fields[7]) == -1) {
    -+  } else if (a2sl(&spwd.sp_expire, fields[7], NULL, 0, 0, LONG_MAX) == -1) {
    - #ifdef    USE_NIS
    -           if (nis_used) {
    -                   spwd.sp_expire = -1;
    -@@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
    -           {
    -                   return 0;
    -           }
    --  } else if (spwd.sp_expire < 0) {
    +-  else if (str2sl(&spwd.sp_expire, fields[7]) == -1)
     -          return 0;
    -   }
    +-  else if (spwd.sp_expire < 0)
    ++  else if (a2sl(&spwd.sp_expire, fields[7], NULL, 0, 0, LONG_MAX) == -1)
    +           return 0;
      
        /*
13:  e9165174 = 13:  9cee75f3 src/check_subid_range.c: Call get_uid() instead of str2sl()
14:  474cb8d6 = 14:  413f764a src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
15:  d3c9e046 = 15:  922ce82f src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
16:  37f2bbee = 16:  e324128d src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
17:  537e5c47 = 17:  7966b682 src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
18:  406269b4 ! 18:  fe0cf332 src/chage.c: Simplify, by calling a2sl() instead of str2sl()
    @@ src/chage.c
      #include "alloc.h"
     -#include "atoi/str2i.h"
     +#include "atoi/a2i.h"
    - #include "prototypes.h"
      #include "defines.h"
      #include "memzero.h"
    + #include "prototypes.h"
     @@ src/chage.c: static int new_fields (void)
      
        SNPRINTF(buf, "%ld", mindays);
    @@ src/chage.c: static int new_fields (void)
                return 0;
     -  }
      
    -   if (-1 == lstchgdate || lstchgdate > LONG_MAX / DAY) {
    -           strcpy (buf, "-1");
    +   if (-1 == lstchgdate || lstchgdate > LONG_MAX / DAY)
    +           strcpy(buf, "-1");
     @@ src/chage.c: static int new_fields (void)
      
        SNPRINTF(buf, "%ld", warndays);
    @@ src/chage.c: static int new_fields (void)
                return 0;
     -  }
      
    -   if (-1 == expdate || LONG_MAX / DAY < expdate) {
    -           strcpy (buf, "-1");
    +   if (-1 == expdate || LONG_MAX / DAY < expdate)
    +           strcpy(buf, "-1");
     @@ src/chage.c: static void process_flags (int argc, char **argv)
                        break;
                case 'I':

@alejandro-colomar
Copy link
Collaborator Author

v2b changes:

  • Rebase on master
$ git range-diff gh/strtoll..gh/getuh strtoll..getuh 
 1:  ca06c536 =  1:  d9ab1ecf lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
 2:  f39d39b5 =  2:  367fb843 lib/getdef.c: getdef_unum(): Fix wrong limit check
 3:  dc98f63e =  3:  92afbb68 lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
 4:  c9d86e9e =  4:  ca682ecc lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
 5:  1ab4608d =  5:  05221444 lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 6:  93439f65 =  6:  2778909f lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
 7:  6d1b9361 =  7:  c7bc89cf lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
 8:  d79de598 =  8:  16ee60e8 lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 9:  db9121fe =  9:  25dcaab2 lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
10:  b01a0529 = 10:  018358d7 lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
11:  0e1edd82 = 11:  e898409a lib/shadow.c: my_sgetspent(): Remove dead code
12:  56f18e94 = 12:  5f5aa6a8 lib/shadow.c: my_sgetspent(): Simplify error handling
13:  9cee75f3 = 13:  4b1a075a src/check_subid_range.c: Call get_uid() instead of str2sl()
14:  413f764a = 14:  2740d61d src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
15:  922ce82f = 15:  a79150cb src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
16:  e324128d = 16:  c7ce1eef src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
17:  7966b682 = 17:  39aa1ee5 src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
18:  fe0cf332 = 18:  0d39c58a src/chage.c: Simplify, by calling a2sl() instead of str2sl()

@alejandro-colomar
Copy link
Collaborator Author

v2c changes:

  • Rebase on master
$ git range-diff gh/strtoll..gh/getuh strtoll..getuh 
 1:  d9ab1ecf =  1:  18952e72 lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
 2:  367fb843 =  2:  0c33b1f1 lib/getdef.c: getdef_unum(): Fix wrong limit check
 3:  92afbb68 =  3:  4eee2f46 lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
 4:  ca682ecc =  4:  2a3e88e5 lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
 5:  05221444 =  5:  f33ad154 lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 6:  2778909f =  6:  f6dfe165 lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
 7:  c7bc89cf =  7:  3050a8e2 lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
 8:  16ee60e8 =  8:  0309a119 lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 9:  25dcaab2 =  9:  6817d131 lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
10:  018358d7 = 10:  98662e5c lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
11:  e898409a = 11:  aceb3132 lib/shadow.c: my_sgetspent(): Remove dead code
12:  5f5aa6a8 = 12:  d72aaf42 lib/shadow.c: my_sgetspent(): Simplify error handling
13:  4b1a075a = 13:  eadbbb59 src/check_subid_range.c: Call get_uid() instead of str2sl()
14:  2740d61d = 14:  2b7c4b6d src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
15:  a79150cb = 15:  107ba466 src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
16:  c7ce1eef = 16:  b16dc391 src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
17:  39aa1ee5 = 17:  2a33c67c src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
18:  0d39c58a = 18:  74ccb043 src/chage.c: Simplify, by calling a2sl() instead of str2sl()

@alejandro-colomar
Copy link
Collaborator Author

v2d changes:

  • Rebase on master
$ git range-diff gh/strtoll..gh/getuh strtoll..getuh 
 1:  18952e72 =  1:  b9774fd7 lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
 2:  0c33b1f1 =  2:  0a1b24ac lib/getdef.c: getdef_unum(): Fix wrong limit check
 3:  4eee2f46 =  3:  97647821 lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
 4:  2a3e88e5 =  4:  52a0567b lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
 5:  f33ad154 =  5:  5024e5fb lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 6:  f6dfe165 =  6:  d2717ea3 lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
 7:  3050a8e2 =  7:  e9d5fac7 lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
 8:  0309a119 =  8:  4dbfec39 lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 9:  6817d131 =  9:  f6f992bc lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
10:  98662e5c = 10:  f2e2ce83 lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
11:  aceb3132 = 11:  a53d20c9 lib/shadow.c: my_sgetspent(): Remove dead code
12:  d72aaf42 = 12:  08c43628 lib/shadow.c: my_sgetspent(): Simplify error handling
13:  eadbbb59 = 13:  31ef23d7 src/check_subid_range.c: Call get_uid() instead of str2sl()
14:  2b7c4b6d = 14:  ecc58525 src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
15:  107ba466 = 15:  3bace38e src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
16:  b16dc391 = 16:  744e03f6 src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
17:  2a33c67c = 17:  2c54da3f src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
18:  74ccb043 = 18:  1304c7fb src/chage.c: Simplify, by calling a2sl() instead of str2sl()

@alejandro-colomar
Copy link
Collaborator Author

v2e changes:

  • Rebase
$ git range-diff gh/strtoll..gh/getuh strtoll..getuh 
 1:  b9774fd7 =  1:  1b50090c lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
 2:  0a1b24ac =  2:  2992a9b1 lib/getdef.c: getdef_unum(): Fix wrong limit check
 3:  97647821 =  3:  b7de9cd0 lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
 4:  52a0567b =  4:  24f2eb29 lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
 5:  5024e5fb =  5:  54c940f8 lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 6:  d2717ea3 =  6:  24fda133 lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
 7:  e9d5fac7 =  7:  6e53104a lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
 8:  4dbfec39 =  8:  edd8518f lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 9:  f6f992bc =  9:  03396c65 lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
10:  f2e2ce83 = 10:  6c3a9651 lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
11:  a53d20c9 = 11:  c3883ff7 lib/shadow.c: my_sgetspent(): Remove dead code
12:  08c43628 = 12:  9cd9ea09 lib/shadow.c: my_sgetspent(): Simplify error handling
13:  31ef23d7 = 13:  21e0afa0 src/check_subid_range.c: Call get_uid() instead of str2sl()
14:  ecc58525 = 14:  17f29a29 src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
15:  3bace38e = 15:  1024afed src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
16:  744e03f6 = 16:  1f67872f src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
17:  2c54da3f = 17:  35c20371 src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
18:  1304c7fb = 18:  d3af3c95 src/chage.c: Simplify, by calling a2sl() instead of str2sl()

@alejandro-colomar
Copy link
Collaborator Author

v2f changes:

  • Rebase
$ git range-diff gh/strtoll..gh/getuh strtoll..getuh 
 1:  1b50090c =  1:  806f0ff5 lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
 2:  2992a9b1 =  2:  f0181f03 lib/getdef.c: getdef_unum(): Fix wrong limit check
 3:  b7de9cd0 =  3:  6d9d10eb lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
 4:  24f2eb29 =  4:  f4692dc4 lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
 5:  54c940f8 =  5:  36614d26 lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 6:  24fda133 =  6:  b9dcbb2b lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
 7:  6e53104a =  7:  9df29b9f lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
 8:  edd8518f =  8:  d0f99086 lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
 9:  03396c65 =  9:  e143fb48 lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
10:  6c3a9651 = 10:  402bec05 lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
11:  c3883ff7 = 11:  a88d11a7 lib/shadow.c: my_sgetspent(): Remove dead code
12:  9cd9ea09 = 12:  2af1a7bf lib/shadow.c: my_sgetspent(): Simplify error handling
13:  21e0afa0 = 13:  aff746c6 src/check_subid_range.c: Call get_uid() instead of str2sl()
14:  17f29a29 = 14:  dbe51a22 src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
15:  1024afed = 15:  5359d519 src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
16:  1f67872f = 16:  321774db src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
17:  35c20371 = 17:  48461308 src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
18:  d3af3c95 = 18:  38704923 src/chage.c: Simplify, by calling a2sl() instead of str2sl()

These overloaded macros allow passing either a const or a non-const
endp, and will call the appropriate function.  This kind of const
overloading has prior art in C23's string functions, such as memchr(3).

Martin suggested using an artificial function pointer in _Generic(3); it
allows switching on various types at the same time.

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf#subsubsection.7.26.5.2>
Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114731>
Co-developed-by: Martin Uecker <muecker@gwdg.de>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
It simplifies the error checking.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
These functions were open-coding get_gid().  Use the actual function.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
…iptor from a string

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Now that we use liba2i's const-generic macros, we can (and must) use a
'const char **' endp where the input string is 'const char *'.

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

Signed-off-by: Alejandro Colomar <alx@kernel.org>
The limit, since it's an unsigned int, should have been UINT_MAX, not
INT_MAX.  By calling a2ui() we can fix that and simplify too.

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

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

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

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

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

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

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

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This reduces indentation.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
spwd.sp_flag is an unsigned long, which can never be negative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Handle negative values as errors from a2sl(), and reuse its
error-handling code.

Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This value represents a uid.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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.

None yet

1 participant