lib/, src/: getulong(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-01-05 16:54:55 -06:00
committed by Serge Hallyn
parent 2d581cb337
commit 2a9b6d80e7
9 changed files with 23 additions and 26 deletions
+1 -1
View File
@@ -347,7 +347,7 @@ unsigned long getdef_ulong (const char *item, unsigned long dflt)
return dflt;
}
if (getulong (d->value, &val) == 0) {
if (getulong(d->value, &val) == -1) {
fprintf (shadow_logfd,
_("configuration error - cannot parse %s value: '%s'"),
item, d->value);
+9 -12
View File
@@ -4,36 +4,33 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <config.h>
#ident "$Id: getlong.c 2763 2009-04-23 09:57:03Z nekral-guest $"
#include <stdlib.h>
#include <errno.h>
#include "prototypes.h"
/*
* getulong - extract an unsigned long integer provided by the numstr string in *result
*
* It supports decimal, hexadecimal or octal representations.
*
* Returns 0 on failure, 1 on success.
*/
int getulong (const char *numstr, /*@out@*/unsigned long *result)
int
getulong(const char *numstr, /*@out@*/unsigned long *result)
{
char *endptr;
unsigned long val;
char *endptr;
errno = 0;
val = strtoul(numstr, &endptr, 0);
if ( ('\0' == *numstr)
|| ('\0' != *endptr)
|| (0 != errno)
) {
return 0;
}
if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno))
return -1;
*result = val;
return 1;
return 0;
}
+3 -3
View File
@@ -58,15 +58,15 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
/* Gather up the ranges from the command line */
mapping = mappings;
for (idx = 0, argidx = 0; idx < ranges; idx++, argidx += 3, mapping++) {
if (!getulong(argv[argidx + 0], &mapping->upper)) {
if (getulong(argv[argidx + 0], &mapping->upper) == -1) {
free(mappings);
return NULL;
}
if (!getulong(argv[argidx + 1], &mapping->lower)) {
if (getulong(argv[argidx + 1], &mapping->lower) == -1) {
free(mappings);
return NULL;
}
if (!getulong(argv[argidx + 2], &mapping->count)) {
if (getulong(argv[argidx + 2], &mapping->count) == -1) {
free(mappings);
return NULL;
}
+3 -3
View File
@@ -104,7 +104,7 @@ static int set_umask (const char *value)
{
unsigned long mask;
if ( (getulong (value, &mask) == 0)
if ( (getulong(value, &mask) == -1)
|| (mask != (mode_t) mask)) {
return 0;
}
@@ -119,7 +119,7 @@ static int check_logins (const char *name, const char *maxlogins)
{
unsigned long limit, count;
if (getulong (maxlogins, &limit) == 0) {
if (getulong(maxlogins, &limit) == -1) {
return 0;
}
@@ -512,7 +512,7 @@ void setup_limits (const struct passwd *info)
if (strncmp (cp, "umask=", 6) == 0) {
unsigned long mask;
if ( (getulong (cp + 6, &mask) == 0)
if ( (getulong(cp + 6, &mask) == -1)
|| (mask != (mode_t) mask)) {
SYSLOG ((LOG_WARN,
"Can't set umask value for user %s",
+1 -1
View File
@@ -78,7 +78,7 @@ do_rlogin (const char *remote_host, char *name, size_t namelen, char *term,
*cp = '\0';
cp++;
if (getulong (cp, &remote_speed) == 0) {
if (getulong(cp, &remote_speed) == -1) {
remote_speed = 9600;
}
}
+1 -1
View File
@@ -175,7 +175,7 @@ struct spwd *sgetspent (const char *string)
if (fields[8][0] == '\0') {
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
} else if (getulong (fields[8], &spwd.sp_flag) == 0) {
} else if (getulong(fields[8], &spwd.sp_flag) == -1) {
return 0;
}
+1 -1
View File
@@ -305,7 +305,7 @@ static struct spwd *my_sgetspent (const char *string)
if (fields[8][0] == '\0') {
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
} else {
if (getulong (fields[8], &spwd.sp_flag) == 0) {
if (getulong(fields[8], &spwd.sp_flag) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
+2 -2
View File
@@ -115,9 +115,9 @@ static void *subordinate_parse (const char *line)
if (i != SUBID_NFIELDS || *fields[0] == '\0' || *fields[1] == '\0' || *fields[2] == '\0')
return NULL;
range.owner = fields[0];
if (getulong (fields[1], &range.start) == 0)
if (getulong(fields[1], &range.start) == -1)
return NULL;
if (getulong (fields[2], &range.count) == 0)
if (getulong(fields[2], &range.count) == -1)
return NULL;
return &range;
+2 -2
View File
@@ -324,7 +324,7 @@ int main (int argc, char **argv)
case 'b':
{
unsigned long inverse_days;
if (getulong (optarg, &inverse_days) == 0) {
if (getulong(optarg, &inverse_days) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -352,7 +352,7 @@ int main (int argc, char **argv)
case 't':
{
unsigned long days;
if (getulong (optarg, &days) == 0) {
if (getulong(optarg, &days) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);