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

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