]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/shadow.c: my_sgetspent(): Simplify error handling
authorAlejandro Colomar <alx@kernel.org>
Tue, 9 Jan 2024 19:20:07 +0000 (20:20 +0100)
committerAlejandro Colomar <alx@kernel.org>
Tue, 2 Jul 2024 20:52:31 +0000 (22:52 +0200)
Handle negative values as errors from a2sl(), and reuse its
error-handling code.

Cc: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/shadow.c

index a593e54a4a7c998a958106e8d1c020886b5e1989..3a867ae2785f65f31dac12ff23087d257dd2a5d0 100644 (file)
@@ -18,6 +18,7 @@
 #include <string.h>
 #include <sys/types.h>
 
+#include "atoi/a2i.h"
 #include "atoi/str2i.h"
 #include "defines.h"
 #include "prototypes.h"
@@ -110,9 +111,7 @@ static struct spwd *my_sgetspent (const char *string)
 
        if (fields[2][0] == '\0')
                spwd.sp_lstchg = -1;
-       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;
 
        /*
@@ -121,9 +120,7 @@ static struct spwd *my_sgetspent (const char *string)
 
        if (fields[3][0] == '\0')
                spwd.sp_min = -1;
-       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;
 
        /*
@@ -132,9 +129,7 @@ static struct spwd *my_sgetspent (const char *string)
 
        if (fields[4][0] == '\0')
                spwd.sp_max = -1;
-       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;
 
        /*
@@ -157,9 +152,7 @@ static struct spwd *my_sgetspent (const char *string)
 
        if (fields[5][0] == '\0')
                spwd.sp_warn = -1;
-       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;
 
        /*
@@ -169,9 +162,7 @@ static struct spwd *my_sgetspent (const char *string)
 
        if (fields[6][0] == '\0')
                spwd.sp_inact = -1;
-       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;
 
        /*
@@ -181,9 +172,7 @@ static struct spwd *my_sgetspent (const char *string)
 
        if (fields[7][0] == '\0')
                spwd.sp_expire = -1;
-       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;
 
        /*