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

Expunge strtoll(3) and strtol(3) #896

Merged
merged 16 commits into from
Jun 29, 2024

Conversation

alejandro-colomar
Copy link
Collaborator

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

Remove all calls to strtoll(3) and strtol(3), and replace them by safer calls like getlong() or getnum().


Revisions

v3 v3 changes:
  • Rebase
$ git range-diff gh/rm_noneg..gh/strtoll rm_noneg..strtoll 
 1:  dcae312d =  1:  bd966bc5 lib/typetraits.h: Add macros that give information about a type
 2:  3088e310 =  2:  afea5fae src/: Use str2[u]l() instead of atoi(3)
 3:  0d3b5e68 =  3:  617570b1 lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
 4:  aecd2148 =  4:  afa3cebc lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
 5:  955fbeec =  5:  a83f9774 lib/: Don't open-code get_gid()
 6:  7e485fa3 =  6:  10ec7b6e lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
 7:  65fd4d27 =  7:  bdf47ee8 lib/: get_pid(): Move function to "atoi/getnum.h"
 8:  3cd8b0ef =  8:  fcfb5bf8 lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
 9:  f22ef57d =  9:  cc310f6b lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
10:  72573c2d = 10:  51690f85 src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
11:  a3350c44 = 11:  0de3198b lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
12:  be1e25ff = 12:  5d89bf4f lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
13:  17194b35 = 13:  16d30dfe lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
v4 v4 changes:
  • Fix const-correctness issue, which has been uncovered by the const-generic liba2i macros.
$ git range-diff rm_noneg gh/strtoll strtoll 
 1:  bd966bc5 =  1:  bd966bc5 lib/typetraits.h: Add macros that give information about a type
 2:  afea5fae =  2:  afea5fae src/: Use str2[u]l() instead of atoi(3)
 3:  617570b1 =  3:  617570b1 lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
 4:  afa3cebc =  4:  afa3cebc lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
 5:  a83f9774 =  5:  a83f9774 lib/: Don't open-code get_gid()
 6:  10ec7b6e =  6:  10ec7b6e lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
 7:  bdf47ee8 =  7:  bdf47ee8 lib/: get_pid(): Move function to "atoi/getnum.h"
 8:  fcfb5bf8 =  8:  fcfb5bf8 lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
 9:  cc310f6b =  9:  cc310f6b lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
10:  51690f85 = 10:  51690f85 src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
11:  0de3198b = 11:  0de3198b lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
12:  5d89bf4f = 12:  5d89bf4f lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
13:  16d30dfe = 13:  16d30dfe lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
 -:  -------- > 14:  cff55356 src/usermod.c: Fix const correctness
v4b
  • Rebase
$ git range-diff gh/rm_noneg..gh/strtoll rm_noneg..strtoll 
 1:  bd966bc5 =  1:  abac335a lib/typetraits.h: Add macros that give information about a type
 2:  afea5fae =  2:  66a8ac5f src/: Use str2[u]l() instead of atoi(3)
 3:  617570b1 =  3:  10c74161 lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
 4:  afa3cebc =  4:  44c7aea3 lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
 5:  a83f9774 =  5:  26d63106 lib/: Don't open-code get_gid()
 6:  10ec7b6e =  6:  84c3bef0 lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
 7:  bdf47ee8 =  7:  5b4afd79 lib/: get_pid(): Move function to "atoi/getnum.h"
 8:  fcfb5bf8 =  8:  3e29da26 lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
 9:  cc310f6b =  9:  53352ba9 lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
10:  51690f85 = 10:  f4b116f9 src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
11:  0de3198b = 11:  e24fbb5f lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
12:  5d89bf4f = 12:  d7f1ca08 lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
13:  16d30dfe = 13:  412f4c9c lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
14:  cff55356 = 14:  86734eae src/usermod.c: Fix const correctness
v4c
  • Rebase
$ git range-diff abac335a^..gh/strtoll shadow/master..strtoll 
 1:  abac335a =  1:  d06c81f2 lib/typetraits.h: Add macros that give information about a type
 2:  66a8ac5f =  2:  b8e914ff src/: Use str2[u]l() instead of atoi(3)
 3:  10c74161 =  3:  105697f2 lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
 4:  44c7aea3 =  4:  36db6c51 lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
 5:  26d63106 =  5:  310b3d80 lib/: Don't open-code get_gid()
 6:  84c3bef0 =  6:  7b9fe7ab lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
 7:  5b4afd79 =  7:  7914f14a lib/: get_pid(): Move function to "atoi/getnum.h"
 8:  3e29da26 =  8:  7d00e662 lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
 9:  53352ba9 =  9:  044396c5 lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
10:  f4b116f9 = 10:  0a81ae8e src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
11:  e24fbb5f = 11:  d9e31c73 lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
12:  d7f1ca08 = 12:  53328602 lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
13:  412f4c9c = 13:  4d4b4717 lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
14:  86734eae = 14:  b85ad7a5 src/usermod.c: Fix const correctness
v4d
  • Rebase
$ git range-diff gh/master..gh/strtoll shadow/master..strtoll 
 1:  d06c81f2 =  1:  0e49d068 lib/typetraits.h: Add macros that give information about a type
 2:  b8e914ff =  2:  c424c125 src/: Use str2[u]l() instead of atoi(3)
 3:  105697f2 =  3:  2a315a9d lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
 4:  36db6c51 =  4:  e4be326d lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
 5:  310b3d80 =  5:  3aaa5e15 lib/: Don't open-code get_gid()
 6:  7b9fe7ab =  6:  f97438b3 lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
 7:  7914f14a =  7:  a66513e3 lib/: get_pid(): Move function to "atoi/getnum.h"
 8:  7d00e662 =  8:  193ca3e0 lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
 9:  044396c5 =  9:  e428f952 lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
10:  0a81ae8e = 10:  25191f59 src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
11:  d9e31c73 = 11:  f15b7334 lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
12:  53328602 = 12:  ab95be16 lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
13:  4d4b4717 = 13:  eb4c2612 lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
14:  b85ad7a5 = 14:  8ee58c14 src/usermod.c: Fix const correctness
v5
  • Use multi-line macros, to make it easier to read so many nested parentheses.
  • Remove unnecessary parentheses.
  • Use uid_t. @hallyn
  • Test type_max() and type_min(). @hallyn
$ git range-diff alx/master gh/strtoll strtoll 
 1:  0e49d068 !  1:  3a8cadb8 lib/typetraits.h: Add macros that give information about a type
    @@ lib/typetraits.h (new)
     +#include "sizeof.h"
     +
     +
    -+#define is_unsigned(x)  (((typeof(x)) -1) > 1)
    -+#define is_signed(x)    (((typeof(x)) -1) < 1)
    ++#define is_unsigned(x)                                                        \
    ++(                                                                             \
    ++  (typeof(x)) -1 > 1                                                    \
    ++)
     +
    -+#define stype_max(T)    ((T) (((((T) 1 << (WIDTHOF(T) - 2)) - 1) << 1) + 1))
    -+#define utype_max(T)    ((T) -1)
    -+#define type_max(T)     ((T) (is_signed(T) ? stype_max(T) : utype_max(T)))
    -+#define type_min(T)     ((T) ~type_max(T))
    ++#define is_signed(x)                                                          \
    ++(                                                                             \
    ++  (typeof(x)) -1 < 1                                                    \
    ++)
    ++
    ++
    ++#define stype_max(T)                                                          \
    ++(                                                                             \
    ++  (T) (((((T) 1 << (WIDTHOF(T) - 2)) - 1) << 1) + 1)                    \
    ++)
    ++
    ++#define utype_max(T)                                                          \
    ++(                                                                             \
    ++  (T) -1                                                                \
    ++)
    ++
    ++#define type_max(T)                                                           \
    ++(                                                                             \
    ++  (T) (is_signed(T) ? stype_max(T) : utype_max(T))                      \
    ++)
    ++
    ++#define type_min(T)                                                           \
    ++(                                                                             \
    ++  (T) ~type_max(T)                                                      \
    ++)
     +
     +
     +#endif  // include guard
 -:  -------- >  2:  6db29249 tests/unit/test_typetraits.c: Add tests for typetraits.h macros
 2:  c424c125 =  3:  af646349 src/: Use str2[u]l() instead of atoi(3)
 3:  2a315a9d =  4:  6adcee8d lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
 4:  e4be326d =  5:  7441f8d8 lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
 5:  3aaa5e15 =  6:  06ff7cc2 lib/: Don't open-code get_gid()
 6:  f97438b3 =  7:  9bff19ee lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
 7:  a66513e3 =  8:  a7e182ff lib/: get_pid(): Move function to "atoi/getnum.h"
 8:  193ca3e0 =  9:  600072eb lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
 9:  e428f952 = 10:  1f52a6ae lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
10:  25191f59 = 11:  eeb9d9c1 src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
11:  f15b7334 = 12:  b1729265 lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
12:  ab95be16 = 13:  cd30ec42 lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
13:  eb4c2612 = 14:  a63f5ea7 lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
14:  8ee58c14 = 15:  0368c108 src/usermod.c: Fix const correctness
 -:  -------- > 16:  5aab8329 src/get_subid_owners.c: Use uid_t for holding UIDs (and GIDs)
v5b
  • Most of it has been reviewed by @hallyn
$ git range-diff alx/master gh/strtoll strtoll 
 1:  3a8cadb8 =  1:  3a8cadb8 lib/typetraits.h: Add macros that give information about a type
 2:  6db29249 =  2:  6db29249 tests/unit/test_typetraits.c: Add tests for typetraits.h macros
 3:  af646349 !  3:  b5abb458 src/: Use str2[u]l() instead of atoi(3)
    @@ Commit message
         atoi(3) easily triggers Undefined Behavior.  Replace it by str2[u]l(),
         which are safe from that, and add type safety too.
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/free_subid_range.c ##
 4:  6adcee8d !  4:  956fe5c5 lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
    @@ Metadata
      ## Commit message ##
         lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/get_gid.c ##
 5:  7441f8d8 !  5:  1180488f lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
    @@ Commit message
         Implement it as an inline function, and add restrict and ATTR_STRING()
         and ATTR_ACCESS() as appropriate.
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/Makefile.am ##
 6:  06ff7cc2 !  6:  c8bda919 lib/: Don't open-code get_gid()
    @@ Commit message
     
         These functions were open-coding get_gid().  Use the actual function.
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/getgr_nam_gid.c ##
 7:  9bff19ee !  7:  5d243ef6 lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
    @@ Metadata
      ## Commit message ##
         lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/get_pid.c ##
 8:  a7e182ff !  8:  df28e67a lib/: get_pid(): Move function to "atoi/getnum.h"
    @@ Commit message
         Implement it as an inline function, and add restrict and ATTR_STRING()
         and ATTR_ACCESS() as appropriate.
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/atoi/getnum.c ##
 9:  600072eb !  9:  fb2d58e6 lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
    @@ Metadata
      ## Commit message ##
         lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/atoi/getnum.c ##
10:  1f52a6ae ! 10:  07a3dc4e lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
    @@ Metadata
      ## Commit message ##
         lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/get_pid.c ##
11:  eeb9d9c1 ! 11:  26e759c8 src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
    @@ Metadata
      ## Commit message ##
         src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/usermod.c ##
12:  b1729265 ! 12:  753192f2 lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
    @@ Metadata
      ## Commit message ##
         lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/get_uid.c ##
13:  cd30ec42 ! 13:  824f6b3c lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
    @@ Commit message
         Implement it as an inline function, and add restrict and ATTR_STRING()
         and ATTR_ACCESS() as appropriate.
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/Makefile.am ##
14:  a63f5ea7 ! 14:  9e9b28c0 lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
    @@ Metadata
      ## Commit message ##
         lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/limits.c ##
15:  0368c108 ! 15:  015087c8 src/usermod.c: Fix const correctness
    @@ Commit message
         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 *'.
     
    +    Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/usermod.c ##
16:  5aab8329 = 16:  ee723b59 src/get_subid_owners.c: Use uid_t for holding UIDs (and GIDs)

@alejandro-colomar
Copy link
Collaborator Author

v2 changes:

  • Rebase to master
$ git range-diff gh/rm_noneg..gh/strtoll rm_noneg..strtoll 
 1:  d987cc23 !  1:  7a754763 lib/typetraits.h: Add macros that give information about a type
    @@ Commit message
     
      ## lib/Makefile.am ##
     @@ lib/Makefile.am: libshadow_la_SOURCES = \
    -   subordinateio.c \
    -   sulog.c \
    +   time/day_to_str.c \
    +   time/day_to_str.h \
        ttytype.c \
     +  typetraits.h \
        tz.c \
 2:  04c3c1ff =  2:  35a75a2f src/: Use str2[u]l() instead of atoi(3)
 3:  901bf98e =  3:  2a5df6b4 lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
 4:  15664d4c !  4:  0245884e lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
    @@ lib/prototypes.h: extern int find_new_sub_gids (gid_t *range_start, unsigned lon
     
      ## lib/sgetgrent.c ##
     @@
    - #include <grp.h>
    + #include <string.h>
      
      #include "alloc.h"
     +#include "atoi/getnum.h"
    @@ lib/sgetgrent.c
     
      ## lib/sgetpwent.c ##
     @@
    - #include "defines.h"
    - #include <stdio.h>
      #include <pwd.h>
    -+
    + #include <string.h>
    + 
     +#include "atoi/getnum.h"
    + #include "defines.h"
      #include "prototypes.h"
      #include "shadowlog_internal.h"
      
 5:  e6d47f2c =  5:  637a8484 lib/: Don't open-code get_gid()
 6:  59b2f005 =  6:  e5b31b34 lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
 7:  23fd5ac6 =  7:  6bd34d8c lib/: get_pid(): Move function to "atoi/getnum.h"
 8:  35b3c86c =  8:  e908ef42 lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
 9:  4e0e9bf1 =  9:  05bd8850 lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
10:  8a4f7943 = 10:  d8fa7301 src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
11:  330dd287 = 11:  ae87a7e9 lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
12:  c77cfdab = 12:  27692802 lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
13:  68ba7031 = 13:  a0b322e2 lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()

@alejandro-colomar
Copy link
Collaborator Author

v2b changes:

  • Rebase on master
$ git range-diff gh/rm_noneg..gh/strtoll rm_noneg..strtoll 
 1:  7a754763 =  1:  6870a0e0 lib/typetraits.h: Add macros that give information about a type
 2:  35a75a2f =  2:  ebba199f src/: Use str2[u]l() instead of atoi(3)
 3:  2a5df6b4 =  3:  a2122723 lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
 4:  0245884e =  4:  6eae04d4 lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
 5:  637a8484 =  5:  debb96f4 lib/: Don't open-code get_gid()
 6:  e5b31b34 =  6:  82a992d3 lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
 7:  6bd34d8c =  7:  58f28b8e lib/: get_pid(): Move function to "atoi/getnum.h"
 8:  e908ef42 =  8:  5eb9fc41 lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
 9:  05bd8850 =  9:  faa7cce1 lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
10:  d8fa7301 = 10:  14ccc58b src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
11:  ae87a7e9 = 11:  fad7d7bb lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
12:  27692802 = 12:  30d634ba lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
13:  a0b322e2 = 13:  97d5ce57 lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()

@alejandro-colomar alejandro-colomar marked this pull request as ready for review May 27, 2024 16:28
@alejandro-colomar
Copy link
Collaborator Author

This is ready for review, @hallyn , @ikerexxe . :)

lib/typetraits.h Outdated Show resolved Hide resolved
src/get_subid_owners.c Outdated Show resolved Hide resolved
Copy link
Member

@hallyn hallyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is great.

Feel free to merge as is, or if you want to add a testcase for the type_min/max, that's great too.

In the case of is_unsigned() and is_signed(), the natural thing would be
to compare to 0:

	#define is_unsigned(x)  (((typeof(x)) -1) > 0)
	#define is_signed(x)    (((typeof(x)) -1) < 0)

However, that would trigger -Wtype-limits, so we compare against 1,
which silences that, and does the same job.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Suggested-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Jun 29, 2024 via email

atoi(3) easily triggers Undefined Behavior.  Replace it by str2[u]l(),
which are safe from that, and add type safety too.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
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.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
These functions were open-coding get_gid().  Use the actual function.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
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.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
…iptor from a string

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
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.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
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 *'.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Suggested-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar alejandro-colomar merged commit 89e4be3 into shadow-maint:master Jun 29, 2024
9 checks passed
@alejandro-colomar alejandro-colomar deleted the strtoll branch June 29, 2024 18:02
@hallyn
Copy link
Member

hallyn commented Jun 30, 2024

Awesome - thank you.

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