Empy or false string conversion (was :fix string to integer conversion)

Ralph Böhme slow at samba.org
Mon Mar 18 17:57:22 UTC 2019


On Wed, Mar 06, 2019 at 11:39:53AM +0100, swen wrote:
>Please review and push if happy.

I think there are a few issues, please see the attached patchset.

I'm wondering wich errno to return for the invalid string case. I'm leaning 
towards also returning EINVAL, not ENODATA. What do you think? Jeremy?

-slow

-- 
Ralph Boehme, Samba Team                https://samba.org/
Samba Developer, SerNet GmbH   https://sernet.de/en/samba/
GPG-Fingerprint   FAE2C6088A24252051C559E4AA1E9B7126399E46
-------------- next part --------------
From 69e0abf2476715d932333a3a5486a01b9f6c35e0 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 09:03:27 +0100
Subject: [PATCH 01/14] lib: modify string conversion wrapper to handle invalid
 strings

The standard string conversion routines convert a "non-number string"
to zero and do not flag an error.
This is changed now by returning ENODATA if no conversion occured.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
---
 lib/util/util.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/util/util.c b/lib/util/util.c
index 19824b550c0..b0bfee978a3 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -60,6 +60,7 @@
  * - wrong base
  * - value overflow
  * - string with a leading "-" indicating a negative number
+ * - no conversion due to empty string or not representing a number
  */
 unsigned long int
 strtoul_err(const char *nptr, char **endptr, int base, int *err)
@@ -78,6 +79,13 @@ strtoul_err(const char *nptr, char **endptr, int base, int *err)
 		*endptr = tmp_endptr;
 	}
 
+	/* got an invalid number-string resulting in no conversion */
+	if (nptr == tmp_endptr) {
+		*err = ENODATA;
+		errno = saved_errno;
+		return val;
+	}
+
 	if (errno != 0) {
 		*err = errno;
 		errno = saved_errno;
@@ -107,6 +115,7 @@ strtoul_err(const char *nptr, char **endptr, int base, int *err)
  * - wrong base
  * - value overflow
  * - string with a leading "-" indicating a negative number
+ * - no conversion due to empty string or not representing a number
  */
 unsigned long long int
 strtoull_err(const char *nptr, char **endptr, int base, int *err)
@@ -125,6 +134,13 @@ strtoull_err(const char *nptr, char **endptr, int base, int *err)
 		*endptr = tmp_endptr;
 	}
 
+	/* got an invalid number-string resulting in no conversion */
+	if (nptr == tmp_endptr) {
+		*err = ENODATA;
+		errno = saved_errno;
+		return val;
+	}
+
 	if (errno != 0) {
 		*err = errno;
 		errno = saved_errno;
-- 
2.17.2


From 770b6180a168af671d33cd1215bdc25480888380 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Mon, 18 Mar 2019 18:33:53 +0100
Subject: [PATCH 02/14] FIXUP: change error checking order; return EINVAL

---
 lib/util/util.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/util/util.c b/lib/util/util.c
index b0bfee978a3..4044dd3a473 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -79,15 +79,15 @@ strtoul_err(const char *nptr, char **endptr, int base, int *err)
 		*endptr = tmp_endptr;
 	}
 
-	/* got an invalid number-string resulting in no conversion */
-	if (nptr == tmp_endptr) {
-		*err = ENODATA;
+	if (errno != 0) {
+		*err = errno;
 		errno = saved_errno;
 		return val;
 	}
 
-	if (errno != 0) {
-		*err = errno;
+	/* got an invalid number-string resulting in no conversion */
+	if (nptr == tmp_endptr) {
+		*err = EINVAL;
 		errno = saved_errno;
 		return val;
 	}
@@ -134,15 +134,15 @@ strtoull_err(const char *nptr, char **endptr, int base, int *err)
 		*endptr = tmp_endptr;
 	}
 
-	/* got an invalid number-string resulting in no conversion */
-	if (nptr == tmp_endptr) {
-		*err = ENODATA;
+	if (errno != 0) {
+		*err = errno;
 		errno = saved_errno;
 		return val;
 	}
 
-	if (errno != 0) {
-		*err = errno;
+	/* got an invalid number-string resulting in no conversion */
+	if (nptr == tmp_endptr) {
+		*err = EINVAL;
 		errno = saved_errno;
 		return val;
 	}
-- 
2.17.2


From 8e2c00703dc7d83ea67df1ceac5c336a2d0c171b Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 09:07:13 +0100
Subject: [PATCH 03/14] lib: Update error check for new string conversion
 wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
---
 source3/lib/interface.c    | 2 +-
 source3/lib/messages_dgm.c | 7 -------
 source3/lib/util_str.c     | 2 +-
 3 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/source3/lib/interface.c b/source3/lib/interface.c
index 342c92a61a2..31066b8b5cc 100644
--- a/source3/lib/interface.c
+++ b/source3/lib/interface.c
@@ -527,7 +527,7 @@ static void interpret_interface(char *token)
 		unsigned long val;
 
 		val = strtoul_err(p, &endp, 0, &error);
-		if (p == endp || (endp && *endp != '\0') || error != 0) {
+		if (error != 0 || *endp != '\0') {
 			DEBUG(2,("interpret_interface: "
 				"can't determine netmask value from %s\n",
 				p));
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index d73a6ad6a7c..545166fb868 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -1470,17 +1470,10 @@ static int messaging_dgm_read_unique(int fd, uint64_t *punique)
 	buf[rw_ret] = '\0';
 
 	unique = strtoull_err(buf, &endptr, 10, &error);
-	if ((unique == 0) && (errno == EINVAL)) {
-		return EINVAL;
-	}
-
 	if (error != 0) {
 		return error;
 	}
 
-	if (endptr[0] != '\n') {
-		return EINVAL;
-	}
 	*punique = unique;
 	return 0;
 }
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index a0095d23978..1a27227fe41 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -859,7 +859,7 @@ uint64_t conv_str_size(const char * str)
 
 	lval = strtoull_err(str, &end, 10, &error);
 
-        if (end == NULL || end == str || error != 0) {
+        if (error != 0) {
                 return 0;
         }
 
-- 
2.17.2


From fc73fba66882e2e4185b9138d5153b6e27ff38a3 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Mon, 18 Mar 2019 18:36:48 +0100
Subject: [PATCH 04/14] FIXUP: keep full consumption check

---
 source3/lib/messages_dgm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index 545166fb868..5a79a234271 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -1474,6 +1474,9 @@ static int messaging_dgm_read_unique(int fd, uint64_t *punique)
 		return error;
 	}
 
+	if (endptr[0] != '\n') {
+		return EINVAL;
+	}
 	*punique = unique;
 	return 0;
 }
-- 
2.17.2


From 891b69d228a7a08c322d0aa1ee4248617cb2c1ff Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 09:20:52 +0100
Subject: [PATCH 05/14] groupdb: Update error check for new string conversion
 wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
---
 source3/groupdb/mapping_tdb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/groupdb/mapping_tdb.c b/source3/groupdb/mapping_tdb.c
index c80ff1f859a..94c29912ce5 100644
--- a/source3/groupdb/mapping_tdb.c
+++ b/source3/groupdb/mapping_tdb.c
@@ -976,7 +976,7 @@ static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
 			 * (objectclass, etc.) */
 			if (strcasecmp_m(name, "gidNumber") == 0) {
 				map->gid = strtoul_err(val, &q, 10, &error);
-				if (*q || (error != 0)) {
+				if (error != 0) {
 					errno = EIO;
 					goto failed;
 				}
@@ -990,7 +990,7 @@ static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
 								&q,
 								10,
 								&error);
-				if (*q || (error != 0)) {
+				if (error != 0) {
 					errno = EIO;
 					goto failed;
 				}
-- 
2.17.2


From 76c9613de3059ec14e38b5d80152d531a091046c Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Mon, 18 Mar 2019 18:38:27 +0100
Subject: [PATCH 06/14] keep full consumption check, Revert "groupdb: Update
 error check for new string conversion wrapper":

This reverts commit 891b69d228a7a08c322d0aa1ee4248617cb2c1ff.
---
 source3/groupdb/mapping_tdb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/groupdb/mapping_tdb.c b/source3/groupdb/mapping_tdb.c
index 94c29912ce5..c80ff1f859a 100644
--- a/source3/groupdb/mapping_tdb.c
+++ b/source3/groupdb/mapping_tdb.c
@@ -976,7 +976,7 @@ static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
 			 * (objectclass, etc.) */
 			if (strcasecmp_m(name, "gidNumber") == 0) {
 				map->gid = strtoul_err(val, &q, 10, &error);
-				if (error != 0) {
+				if (*q || (error != 0)) {
 					errno = EIO;
 					goto failed;
 				}
@@ -990,7 +990,7 @@ static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
 								&q,
 								10,
 								&error);
-				if (error != 0) {
+				if (*q || (error != 0)) {
 					errno = EIO;
 					goto failed;
 				}
-- 
2.17.2


From f3ca909835afe51bf57288bd7ef8d9d06c639dfb Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 09:29:13 +0100
Subject: [PATCH 07/14] utils: Update error check for new string conversion
 wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 source3/utils/net_idmap.c      | 10 ++--------
 source3/utils/net_sam.c        |  2 +-
 source3/utils/pdbedit.c        |  5 +----
 source3/utils/regedit_dialog.c |  8 +++-----
 4 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c
index f6c9f3a1a3d..d1a6db95921 100644
--- a/source3/utils/net_idmap.c
+++ b/source3/utils/net_idmap.c
@@ -631,16 +631,10 @@ static bool parse_uint32(const char *str, uint32_t *result)
 	int error = 0;
 
 	val = strtoul_err(str, &endptr, 10, &error);
-
-	if (str == endptr) {
-		return false;
-	}
-	if (*endptr != '\0') {
-		return false;
-	}
-	if (error != 0) {
+	if (error != 0 || *endptr != '\0') {
 		return false;
 	}
+
 	*result = val;		/* Potential crop */
 	return true;
 }
diff --git a/source3/utils/net_sam.c b/source3/utils/net_sam.c
index fc2a7baacef..164d9408c56 100644
--- a/source3/utils/net_sam.c
+++ b/source3/utils/net_sam.c
@@ -503,7 +503,7 @@ static int net_sam_policy_set(struct net_context *c, int argc, const char **argv
 	else {
 		value = strtoul_err(argv[1], &endptr, 10, &err);
 
-		if ((endptr == argv[1]) || (endptr[0] != '\0') || (err != 0)) {
+		if (err != 0 || *endptr != '\0') {
 			d_printf(_("Unable to set policy \"%s\"! Invalid value "
 				 "\"%s\".\n"),
 				 account_policy, argv[1]);
diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c
index c80d5411b00..462c753217e 100644
--- a/source3/utils/pdbedit.c
+++ b/source3/utils/pdbedit.c
@@ -602,10 +602,7 @@ static int set_user_info(const char *username, const char *fullname,
 			uint32_t num;
 
 			num = strtoul_err(kickoff_time, &endptr, 10, &error);
-			if ((endptr == kickoff_time) ||
-			    (endptr[0] != '\0') ||
-			    (error != 0))
-			{
+			if (error != 0 || *endptr != '\0') {
 				fprintf(stderr, "Failed to parse kickoff time\n");
 				return -1;
 			}
diff --git a/source3/utils/regedit_dialog.c b/source3/utils/regedit_dialog.c
index aeea70ac22e..7dd9f0fadea 100644
--- a/source3/utils/regedit_dialog.c
+++ b/source3/utils/regedit_dialog.c
@@ -1029,7 +1029,6 @@ bool dialog_section_text_field_get_int(struct dialog_section *section,
 bool dialog_section_text_field_get_uint(struct dialog_section *section,
 				        unsigned long long *out)
 {
-	bool rv;
 	const char *buf;
 	char *endp;
 	int error = 0;
@@ -1043,12 +1042,11 @@ bool dialog_section_text_field_get_uint(struct dialog_section *section,
 		return false;
 	}
 	*out = strtoull_err(buf, &endp, 0, &error);
-	rv = true;
-	if (endp == buf || endp == NULL || endp[0] != '\0' || error != 0) {
-		rv = false;
+	if (error != 0 || *endp != '\0') {
+		return false;
 	}
 
-	return rv;
+	return true;
 }
 
 /* hex editor field */
-- 
2.17.2


From 4eae0b342b27ec720581984a7fda52f764420f52 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 09:34:10 +0100
Subject: [PATCH 08/14] modules: Update error check for new string conversion
 wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 source3/modules/vfs_snapper.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/source3/modules/vfs_snapper.c b/source3/modules/vfs_snapper.c
index 0f52f9e71c5..fdd99a2cca5 100644
--- a/source3/modules/vfs_snapper.c
+++ b/source3/modules/vfs_snapper.c
@@ -1216,7 +1216,6 @@ static NTSTATUS snapper_snap_path_to_id(TALLOC_CTX *mem_ctx,
 {
 	char *path_dup;
 	char *str_idx;
-	char *str_end;
 	uint32_t snap_id;
 	int error = 0;
 
@@ -1251,8 +1250,8 @@ static NTSTATUS snapper_snap_path_to_id(TALLOC_CTX *mem_ctx,
 	}
 
 	str_idx++;
-	snap_id = strtoul_err(str_idx, &str_end, 10, &error);
-	if (error != 0 || str_idx == str_end) {
+	snap_id = strtoul_err(str_idx, NULL, 10, &error);
+	if (error != 0) {
 		talloc_free(path_dup);
 		return NT_STATUS_INVALID_PARAMETER;
 	}
-- 
2.17.2


From e4566d38dd20f6803e6c3deae693a89abcbd1f5d Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 09:43:53 +0100
Subject: [PATCH 09/14] ctdb-protocol: Update error check for new string
 conversion wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 ctdb/protocol/protocol_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c
index 99dbe82404d..1dfa49b9dc2 100644
--- a/ctdb/protocol/protocol_util.c
+++ b/ctdb/protocol/protocol_util.c
@@ -288,7 +288,7 @@ int ctdb_sock_addr_from_string(const char *str,
 	}
 
 	port = strtoul_err(p+1, &endp, 10, &ret);
-	if (endp == p+1 || *endp != '\0' || ret != 0) {
+	if (ret != 0 || *endp != '\0') {
 		/* Empty string or trailing garbage */
 		return EINVAL;
 	}
@@ -327,7 +327,7 @@ int ctdb_sock_addr_mask_from_string(const char *str,
 	}
 
 	m = strtoul_err(p+1, &endp, 10, &ret);
-	if (endp == p+1 || *endp != '\0' || ret != 0) {
+	if (ret != 0 || *endp != '\0') {
 		/* Empty string or trailing garbage */
 		return EINVAL;
 	}
-- 
2.17.2


From 15756be2c5a096dee034052dcc9a28302f50009f Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 09:48:24 +0100
Subject: [PATCH 10/14] ctdb-tools: Update error check for new string
 conversion wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 ctdb/tools/ctdb.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 8140d7337c5..98f1868e8eb 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -325,10 +325,9 @@ static bool parse_nodestring(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 		tok = strtok(ns, ",");
 		while (tok != NULL) {
 			uint32_t pnn;
-			char *endptr;
 
-			pnn = (uint32_t)strtoul_err(tok, &endptr, 0, &error);
-			if (error != 0 || (pnn == 0 && tok == endptr)) {
+			pnn = (uint32_t)strtoul_err(tok, NULL, 0, &error);
+			if (error != 0) {
 				fprintf(stderr, "Invalid node %s\n", tok);
 					return false;
 			}
-- 
2.17.2


From d3afeb9b0b04eeea0e1b1be82506b94ef774526c Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 10:02:53 +0100
Subject: [PATCH 11/14] TODO common-lib: Update error check for new string
 conversion wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
---
 lib/ldb-samba/ldb_matching_rules.c | 14 ++------------
 lib/util/access.c                  |  2 +-
 lib/util/util_str.c                |  4 ++--
 3 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/lib/ldb-samba/ldb_matching_rules.c b/lib/ldb-samba/ldb_matching_rules.c
index 7387c12f10d..492a8e71773 100644
--- a/lib/ldb-samba/ldb_matching_rules.c
+++ b/lib/ldb-samba/ldb_matching_rules.c
@@ -393,12 +393,7 @@ static int dsdb_match_for_dns_to_tombstone_time(struct ldb_context *ldb,
 			return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 		}
 		tombstone_time = strtoull_err(s, &p, 10, &error);
-		if (p == NULL ||
-		    p == s ||
-		    *p != '\0' ||
-		    error != 0 ||
-		    tombstone_time == ULLONG_MAX)
-		{
+		if (error != 0 || *p != '\0' || tombstone_time == ULLONG_MAX) {
 			DBG_ERR("Invalid timestamp string passed\n");
 			return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 		}
@@ -529,12 +524,7 @@ static int dsdb_match_for_expunge(struct ldb_context *ldb,
 			return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 		}
 		tombstone_time = strtoull_err(s, &p, 10, &error);
-		if (p == NULL ||
-		    p == s ||
-		    *p != '\0' ||
-		    error != 0 ||
-		    tombstone_time == ULLONG_MAX)
-		{
+		if (error != 0 || *p != '\0' || tombstone_time == ULLONG_MAX) {
 			return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 		}
 	}
diff --git a/lib/util/access.c b/lib/util/access.c
index a05a47c15b2..960fe4b066c 100644
--- a/lib/util/access.c
+++ b/lib/util/access.c
@@ -75,7 +75,7 @@ static bool masked_match(const char *tok, const char *slash, const char *s)
 		unsigned long val;
 
 		val = strtoul_err(slash+1, &endp, 0, &error);
-		if (slash+1 == endp || (endp && *endp != '\0') || error != 0) {
+		if (error != 0 || *endp != '\0') {
 			return false;
 		}
 		if (!make_netmask(&ss_mask, &ss_tok, val)) {
diff --git a/lib/util/util_str.c b/lib/util/util_str.c
index 447919b087b..29a44836bde 100644
--- a/lib/util/util_str.c
+++ b/lib/util/util_str.c
@@ -70,7 +70,7 @@ _PUBLIC_ bool conv_str_size_error(const char * str, uint64_t * val)
 	}
 
 	lval = strtoull_err(str, &end, 10, &error);
-	if (end == NULL || end == str || error != 0) {
+	if (error != 0) {
 		return false;
 	}
 
@@ -112,7 +112,7 @@ _PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val)
 	}
 
 	lval = strtoull_err(str, &end, 10, &error);
-	if (end == NULL || *end != '\0' || end == str || error != 0) {
+	if (error != 0 || *end != '\0') {
 		return false;
 	}
 
-- 
2.17.2


From 5316b157cdf82190e3d067a9bb04cea68146b0ed Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Mon, 18 Mar 2019 18:49:00 +0100
Subject: [PATCH 12/14] FIXUP: remove overflow check

---
 lib/ldb-samba/ldb_matching_rules.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/ldb-samba/ldb_matching_rules.c b/lib/ldb-samba/ldb_matching_rules.c
index 492a8e71773..0754e7e066b 100644
--- a/lib/ldb-samba/ldb_matching_rules.c
+++ b/lib/ldb-samba/ldb_matching_rules.c
@@ -393,7 +393,7 @@ static int dsdb_match_for_dns_to_tombstone_time(struct ldb_context *ldb,
 			return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 		}
 		tombstone_time = strtoull_err(s, &p, 10, &error);
-		if (error != 0 || *p != '\0' || tombstone_time == ULLONG_MAX) {
+		if (error != 0 || *p != '\0') {
 			DBG_ERR("Invalid timestamp string passed\n");
 			return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 		}
@@ -524,7 +524,7 @@ static int dsdb_match_for_expunge(struct ldb_context *ldb,
 			return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 		}
 		tombstone_time = strtoull_err(s, &p, 10, &error);
-		if (error != 0 || *p != '\0' || tombstone_time == ULLONG_MAX) {
+		if (error != 0 || *p != '\0') {
 			return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 		}
 	}
-- 
2.17.2


From dc6829281fef5c398bad42c3d563445139e370fa Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 10:06:35 +0100
Subject: [PATCH 13/14] libcli: Update error check for new string conversion
 wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 libcli/security/dom_sid.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcli/security/dom_sid.c b/libcli/security/dom_sid.c
index ca7fd874752..ac34a92f19c 100644
--- a/libcli/security/dom_sid.c
+++ b/libcli/security/dom_sid.c
@@ -149,7 +149,7 @@ bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
 	}
 
 	conv = strtoul_err(p, &q, 10, &error);
-	if (!q || (*q != '-') || conv > UINT8_MAX || error != 0) {
+	if (error != 0 || (*q != '-') || conv > UINT8_MAX) {
 		goto format_error;
 	}
 	sidout->sid_rev_num = (uint8_t) conv;
@@ -161,7 +161,7 @@ bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
 
 	/* get identauth */
 	conv = strtoull_err(q, &q, 0, &error);
-	if (!q || conv & AUTHORITY_MASK || error != 0) {
+	if (conv & AUTHORITY_MASK || error != 0) {
 		goto format_error;
 	}
 
@@ -190,7 +190,7 @@ bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
 		}
 
 		conv = strtoull_err(q, &end, 10, &error);
-		if (end == q || conv > UINT32_MAX || error != 0) {
+		if (conv > UINT32_MAX || error != 0) {
 			goto format_error;
 		}
 
-- 
2.17.2


From d2fa3a0986374aa56e6eca1101a25ca9f0c069cd Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 6 Mar 2019 10:11:39 +0100
Subject: [PATCH 14/14] source4: Update error check for new string conversion
 wrapper

The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 source4/dsdb/samdb/ldb_modules/samldb.c | 2 +-
 source4/lib/socket/interface.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c
index ae99ebbe9ed..ea6e68b371a 100644
--- a/source4/dsdb/samdb/ldb_modules/samldb.c
+++ b/source4/dsdb/samdb/ldb_modules/samldb.c
@@ -3337,7 +3337,7 @@ static int verify_cidr(const char *cidr)
 		goto error;
 	}
 
-	if (*endptr != '\0' || endptr == slash + 1 || error != 0){
+	if (error != 0 || *endptr != '\0'){
 		DBG_INFO("CIDR mask is not a proper integer: %s\n", cidr);
 		goto error;
 	}
diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c
index 494cbd4fdd2..9bf002c2f01 100644
--- a/source4/lib/socket/interface.c
+++ b/source4/lib/socket/interface.c
@@ -228,7 +228,7 @@ static void interpret_interface(TALLOC_CTX *mem_ctx,
 		int error = 0;
 
 		unsigned long val = strtoul_err(p, &endp, 0, &error);
-		if (p == endp || (endp && *endp != '\0') || error != 0) {
+		if (error != 0 || *endp != '\0') {
 			DEBUG(2,("interpret_interface: "
 				"can't determine netmask value from %s\n",
 				p));
-- 
2.17.2



More information about the samba-technical mailing list