lib/shadow.c: my_sgetspent(): Simplify error handling
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>
This commit is contained in:
25
lib/shadow.c
25
lib/shadow.c
@@ -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;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user