Skip to content

Commit

Permalink
Reset errno before strtol
Browse files Browse the repository at this point in the history
This sets errno to 0 before strotol calls after which the errno
is being checked.

Per man 3 strtol:
Since  strtol()  can  legitimately  return 0, LONG_MAX, or
LONG_MIN (LLONG_MAX or LLONG_MIN for strtoll()) on both success and
failure, the calling program should set errno to 0 before the call, and
then determine if an error occurred by checking whether errno has a
nonzero value after the call.

This is inspired by #1861.
  • Loading branch information
jan-cerny committed Jul 25, 2022
1 parent 963edcd commit 55b09ba
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/OVAL/probes/independent/sql57_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ static int dbURIInfo_parse(dbURIInfo_t *info, const char *conn)
matchitem1(tok, 'c',
"onnecttimeout", tmp);
if (tmp != NULL) {
errno = 0;
info->conn_timeout = strtol(tmp, NULL, 10);

if (errno == ERANGE || errno == EINVAL)
Expand Down
1 change: 1 addition & 0 deletions src/OVAL/probes/independent/sql_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ static int dbURIInfo_parse(dbURIInfo_t *info, const char *conn)
matchitem1(tok, 'c',
"onnecttimeout", tmp);
if (tmp != NULL) {
errno = 0;
info->conn_timeout = strtol(tmp, NULL, 10);

if (errno == ERANGE || errno == EINVAL)
Expand Down
1 change: 1 addition & 0 deletions src/OVAL/probes/oval_fts.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ OVAL_FTS *oval_fts_open_prefixed(const char *prefix, SEXP_t *path, SEXP_t *filen
/* max_depth */
PROBE_ENT_AREF(behaviors, r0, "max_depth", return NULL;);
SEXP_string_cstr_r(r0, cstr_buff, sizeof cstr_buff - 1);
errno = 0;
max_depth = strtol(cstr_buff, NULL, 10);
if (errno == EINVAL || errno == ERANGE) {
dE("Invalid value of the `%s' attribute: %s", "recurse_direction", cstr_buff);
Expand Down
1 change: 1 addition & 0 deletions src/OVAL/probes/unix/xinetd_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ int op_assign_bool(void *var, char *val)
*((bool *)(var)) = false;
} else {
char *endptr = NULL;
errno = 0;
*((bool *)(var)) = (bool) strtol (val, &endptr, 2);
if (errno == EINVAL || errno == ERANGE) {
return -1;
Expand Down

0 comments on commit 55b09ba

Please sign in to comment.