Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use str* API to check for valid numeric value #677

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions server/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,44 +116,40 @@ static void ups_update(const char *fn, const char *name, const char *desc)
/* return 1 if usable, 0 if not */
static int parse_upsd_conf_args(int numargs, char **arg)
{
unsigned int temp;

/* everything below here uses up through arg[1] */
if (numargs < 2)
return 0;

/* MAXAGE <seconds> */
if (!strcmp(arg[0], "MAXAGE")) {
if (isdigit(arg[1])) {
maxage = atoi(arg[1]);
if (str_to_uint(arg[1], &temp, 10)) {
maxage = temp;
return 1;
}
else {
upslogx(LOG_ERR, "MAXAGE has non numeric value (%s)!", arg[1]);
return 0;
}
upslogx(LOG_ERR, "Could not convert MAXAGE (%s) to an unsigned int (%s)!", arg[1], strerror(errno));
aquette marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}

/* TRACKINGDELAY <seconds> */
if (!strcmp(arg[0], "TRACKINGDELAY")) {
if (isdigit(arg[1])) {
tracking_delay = atoi(arg[1]);
if (str_to_uint(arg[1], &temp, 10)) {
tracking_delay = temp;
return 1;
}
else {
upslogx(LOG_ERR, "TRACKINGDELAY has non numeric value (%s)!", arg[1]);
return 0;
}
upslogx(LOG_ERR, "Could not convert TRACKINGDELAY (%s) to an unsigned int (%s)!", arg[1], strerror(errno));
return 0;
}

/* MAXCONN <connections> */
if (!strcmp(arg[0], "MAXCONN")) {
if (isdigit(arg[1])) {
maxconn = atoi(arg[1]);
if (str_to_uint(arg[1], &temp, 10)) {
maxconn = temp;
return 1;
}
else {
upslogx(LOG_ERR, "MAXCONN has non numeric value (%s)!", arg[1]);
return 0;
}
upslogx(LOG_ERR, "Could not convert MAXCONN (%s) to an unsigned int (%s)!", arg[1], strerror(errno));
return 0;
}

/* STATEPATH <dir> */
Expand Down Expand Up @@ -187,14 +183,12 @@ static int parse_upsd_conf_args(int numargs, char **arg)
#ifdef WITH_CLIENT_CERTIFICATE_VALIDATION
/* CERTREQUEST (0 | 1 | 2) */
if (!strcmp(arg[0], "CERTREQUEST")) {
if (isdigit(arg[1])) {
certrequest = atoi(arg[1]);
if (str_to_uint(arg[1], &temp, 10)) {
certrequest = temp;
return 1;
}
else {
upslogx(LOG_ERR, "CERTREQUEST has non numeric value (%s)!", arg[1]);
return 0;
}
upslogx(LOG_ERR, "Could not convert CERTREQUEST (%s) to an unsigned int (%s)!", arg[1], strerror(errno));
return 0;
}
#endif /* WITH_CLIENT_CERTIFICATE_VALIDATION */
#endif /* WITH_OPENSSL | WITH_NSS */
Expand Down