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

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