Blame SOURCES/openscap-1.3.7-PR-1875-reset-errno-strtol.patch

d7d613
From 55b09ba184c1803a5e1454c44e9e9a5c578dd741 Mon Sep 17 00:00:00 2001
d7d613
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
d7d613
Date: Mon, 25 Jul 2022 17:10:17 +0200
d7d613
Subject: [PATCH] Reset errno before strtol
d7d613
d7d613
This sets errno to 0 before strotol calls after which the errno
d7d613
is being checked.
d7d613
d7d613
Per man 3 strtol:
d7d613
Since  strtol()  can  legitimately  return 0, LONG_MAX, or
d7d613
LONG_MIN (LLONG_MAX or LLONG_MIN for strtoll()) on both success and
d7d613
failure, the calling program should set errno to 0 before the call, and
d7d613
then determine if an error occurred by checking whether errno has a
d7d613
nonzero value after the call.
d7d613
d7d613
This is inspired by https://github.com/OpenSCAP/openscap/pull/1861.
d7d613
---
d7d613
 src/OVAL/probes/independent/sql57_probe.c | 1 +
d7d613
 src/OVAL/probes/independent/sql_probe.c   | 1 +
d7d613
 src/OVAL/probes/oval_fts.c                | 1 +
d7d613
 src/OVAL/probes/unix/xinetd_probe.c       | 1 +
d7d613
 4 files changed, 4 insertions(+)
d7d613
d7d613
diff --git a/src/OVAL/probes/independent/sql57_probe.c b/src/OVAL/probes/independent/sql57_probe.c
d7d613
index ce1466635c..2b35750ee2 100644
d7d613
--- a/src/OVAL/probes/independent/sql57_probe.c
d7d613
+++ b/src/OVAL/probes/independent/sql57_probe.c
d7d613
@@ -216,6 +216,7 @@ static int dbURIInfo_parse(dbURIInfo_t *info, const char *conn)
d7d613
 			matchitem1(tok, 'c',
d7d613
 				   "onnecttimeout", tmp);
d7d613
 			if (tmp != NULL) {
d7d613
+				errno = 0;
d7d613
 				info->conn_timeout = strtol(tmp, NULL, 10);
d7d613
 
d7d613
 				if (errno == ERANGE || errno == EINVAL)
d7d613
diff --git a/src/OVAL/probes/independent/sql_probe.c b/src/OVAL/probes/independent/sql_probe.c
d7d613
index 2ede89d031..71ba3c08c3 100644
d7d613
--- a/src/OVAL/probes/independent/sql_probe.c
d7d613
+++ b/src/OVAL/probes/independent/sql_probe.c
d7d613
@@ -216,6 +216,7 @@ static int dbURIInfo_parse(dbURIInfo_t *info, const char *conn)
d7d613
 			matchitem1(tok, 'c',
d7d613
 				   "onnecttimeout", tmp);
d7d613
 			if (tmp != NULL) {
d7d613
+				errno = 0;
d7d613
 				info->conn_timeout = strtol(tmp, NULL, 10);
d7d613
 
d7d613
 				if (errno == ERANGE || errno == EINVAL)
d7d613
diff --git a/src/OVAL/probes/oval_fts.c b/src/OVAL/probes/oval_fts.c
d7d613
index 1364159c90..f9d0a0c1fd 100644
d7d613
--- a/src/OVAL/probes/oval_fts.c
d7d613
+++ b/src/OVAL/probes/oval_fts.c
d7d613
@@ -729,6 +729,7 @@ OVAL_FTS *oval_fts_open_prefixed(const char *prefix, SEXP_t *path, SEXP_t *filen
d7d613
 	/* max_depth */
d7d613
 	PROBE_ENT_AREF(behaviors, r0, "max_depth", return NULL;);
d7d613
 	SEXP_string_cstr_r(r0, cstr_buff, sizeof cstr_buff - 1);
d7d613
+	errno = 0;
d7d613
 	max_depth = strtol(cstr_buff, NULL, 10);
d7d613
 	if (errno == EINVAL || errno == ERANGE) {
d7d613
 		dE("Invalid value of the `%s' attribute: %s", "recurse_direction", cstr_buff);
d7d613
diff --git a/src/OVAL/probes/unix/xinetd_probe.c b/src/OVAL/probes/unix/xinetd_probe.c
d7d613
index b3375500db..703a07f513 100644
d7d613
--- a/src/OVAL/probes/unix/xinetd_probe.c
d7d613
+++ b/src/OVAL/probes/unix/xinetd_probe.c
d7d613
@@ -1280,6 +1280,7 @@ int op_assign_bool(void *var, char *val)
d7d613
 		*((bool *)(var)) = false;
d7d613
 	} else {
d7d613
 		char *endptr = NULL;
d7d613
+		errno = 0;
d7d613
 		*((bool *)(var)) = (bool) strtol (val, &endptr, 2);
d7d613
 		if (errno == EINVAL || errno == ERANGE) {
d7d613
 			return -1;