Skip to content

Commit dd6cdbe

Browse files
committed
Use str* API to check for valid numeric value
Closes networkupstools#676 Signed-off-by: Arnaud Quette <ArnaudQuette@eaton.com>
1 parent ea0a994 commit dd6cdbe

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

server/conf.c

+18-24
Original file line numberDiff line numberDiff line change
@@ -116,44 +116,40 @@ static void ups_update(const char *fn, const char *name, const char *desc)
116116
/* return 1 if usable, 0 if not */
117117
static int parse_upsd_conf_args(int numargs, char **arg)
118118
{
119+
unsigned int temp;
120+
119121
/* everything below here uses up through arg[1] */
120122
if (numargs < 2)
121123
return 0;
122124

123125
/* MAXAGE <seconds> */
124126
if (!strcmp(arg[0], "MAXAGE")) {
125-
if (isdigit(arg[1])) {
126-
maxage = atoi(arg[1]);
127+
if (str_to_uint(arg[1], &temp, 10)) {
128+
maxage = temp;
127129
return 1;
128130
}
129-
else {
130-
upslogx(LOG_ERR, "MAXAGE has non numeric value (%s)!", arg[1]);
131-
return 0;
132-
}
131+
upslogx(LOG_ERR, "Could not convert MAXAGE (%s) to an unsigned int (%s)!", arg[1], strerror(errno));
132+
return 0;
133133
}
134134

135135
/* TRACKINGDELAY <seconds> */
136136
if (!strcmp(arg[0], "TRACKINGDELAY")) {
137-
if (isdigit(arg[1])) {
138-
tracking_delay = atoi(arg[1]);
137+
if (str_to_uint(arg[1], &temp, 10)) {
138+
tracking_delay = temp;
139139
return 1;
140140
}
141-
else {
142-
upslogx(LOG_ERR, "TRACKINGDELAY has non numeric value (%s)!", arg[1]);
143-
return 0;
144-
}
141+
upslogx(LOG_ERR, "Could not convert TRACKINGDELAY (%s) to an unsigned int (%s)!", arg[1], strerror(errno));
142+
return 0;
145143
}
146144

147145
/* MAXCONN <connections> */
148146
if (!strcmp(arg[0], "MAXCONN")) {
149-
if (isdigit(arg[1])) {
150-
maxconn = atoi(arg[1]);
147+
if (str_to_uint(arg[1], &temp, 10)) {
148+
maxconn = temp;
151149
return 1;
152150
}
153-
else {
154-
upslogx(LOG_ERR, "MAXCONN has non numeric value (%s)!", arg[1]);
155-
return 0;
156-
}
151+
upslogx(LOG_ERR, "Could not convert MAXCONN (%s) to an unsigned int (%s)!", arg[1], strerror(errno));
152+
return 0;
157153
}
158154

159155
/* STATEPATH <dir> */
@@ -187,14 +183,12 @@ static int parse_upsd_conf_args(int numargs, char **arg)
187183
#ifdef WITH_CLIENT_CERTIFICATE_VALIDATION
188184
/* CERTREQUEST (0 | 1 | 2) */
189185
if (!strcmp(arg[0], "CERTREQUEST")) {
190-
if (isdigit(arg[1])) {
191-
certrequest = atoi(arg[1]);
186+
if (str_to_uint(arg[1], &temp, 10)) {
187+
certrequest = temp;
192188
return 1;
193189
}
194-
else {
195-
upslogx(LOG_ERR, "CERTREQUEST has non numeric value (%s)!", arg[1]);
196-
return 0;
197-
}
190+
upslogx(LOG_ERR, "Could not convert CERTREQUEST (%s) to an unsigned int (%s)!", arg[1], strerror(errno));
191+
return 0;
198192
}
199193
#endif /* WITH_CLIENT_CERTIFICATE_VALIDATION */
200194
#endif /* WITH_OPENSSL | WITH_NSS */

0 commit comments

Comments
 (0)