From: Alejandro Colomar Date: Tue, 9 Jan 2024 19:20:07 +0000 (+0100) Subject: lib/shadow.c: my_sgetspent(): Simplify error handling X-Git-Tag: 4.17.0-rc1~156 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a11ae5cf29b95f0fae16a4b45a1e40c44c6fe8a7;p=thirdparty%2Fshadow.git lib/shadow.c: my_sgetspent(): Simplify error handling Handle negative values as errors from a2sl(), and reuse its error-handling code. Cc: Iker Pedrosa Reviewed-by: "Serge E. Hallyn" Signed-off-by: Alejandro Colomar --- diff --git a/lib/shadow.c b/lib/shadow.c index a593e54a4..3a867ae27 100644 --- a/lib/shadow.c +++ b/lib/shadow.c @@ -18,6 +18,7 @@ #include #include +#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; /*