[PATCHSET] Fix and add -Werror=strict-overflow -Wstrict-overflow=2

Andreas Schneider asn at samba.org
Tue Jan 16 14:13:43 UTC 2018


On Thursday, 7 December 2017 20:37:15 CET Andreas Schneider via samba-
technical wrote:
> Hello,
> 
> I've worked on a patchset to turn on:
> 
>  -Werror=strict-overflow -Wstrict-overflow=2
> 
> 
> The attached patchset fixes all the issues found with the compiler warning
> turned on. The first part is pretty obvious int -> size_t but then there are
> were some harder nuts to crack. I hope I got all right but a careful review
> would be great!
> 
> I'm also fine opening a bug and backport them if someones thinks it is worth
> to have it in 4.7.
> 
> 
> Review much appreciated.

Rebased patchset attached.

Please review and push if OK.


Thanks,


	Andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
Samba Team                             asn at samba.org
www.samba.org
-------------- next part --------------
>From a60d68e00e3203f77635011bc9c42185267c9caa Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 20:26:40 +0100
Subject: [PATCH 01/41] heimdal: Fix size types

This fixes compilation with -Wstrict-overflow=2

Upstream pull request:
https://github.com/heimdal/heimdal/pull/354

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/heimdal/lib/asn1/gen.c         | 4 ++--
 source4/heimdal/lib/hx509/cert.c       | 3 ++-
 source4/heimdal/lib/krb5/config_file.c | 2 +-
 source4/heimdal/lib/krb5/keytab_any.c  | 2 +-
 source4/heimdal/lib/roken/resolve.c    | 2 +-
 5 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/source4/heimdal/lib/asn1/gen.c b/source4/heimdal/lib/asn1/gen.c
index fd833dbd76f..919a7076ac1 100644
--- a/source4/heimdal/lib/asn1/gen.c
+++ b/source4/heimdal/lib/asn1/gen.c
@@ -502,7 +502,7 @@ is_primitive_type(int type)
 }
 
 static void
-space(int level)
+space(size_t level)
 {
     while(level-- > 0)
 	fprintf(headerfile, "  ");
@@ -531,7 +531,7 @@ have_ellipsis(Type *t)
 }
 
 static void
-define_asn1 (int level, Type *t)
+define_asn1 (size_t level, Type *t)
 {
     switch (t->type) {
     case TType:
diff --git a/source4/heimdal/lib/hx509/cert.c b/source4/heimdal/lib/hx509/cert.c
index 329fc179cb5..190bdb48a4f 100644
--- a/source4/heimdal/lib/hx509/cert.c
+++ b/source4/heimdal/lib/hx509/cert.c
@@ -1977,7 +1977,8 @@ hx509_verify_path(hx509_context context,
 {
     hx509_name_constraints nc;
     hx509_path path;
-    int ret, proxy_cert_depth, selfsigned_depth, diff;
+    int ret, diff;
+    size_t proxy_cert_depth, selfsigned_depth;
     size_t i, k;
     enum certtype type;
     Name proxy_issuer;
diff --git a/source4/heimdal/lib/krb5/config_file.c b/source4/heimdal/lib/krb5/config_file.c
index 4ac25ae2870..2748f481d66 100644
--- a/source4/heimdal/lib/krb5/config_file.c
+++ b/source4/heimdal/lib/krb5/config_file.c
@@ -925,7 +925,7 @@ krb5_config_vget_strings(krb5_context context,
 			 va_list args)
 {
     char **strings = NULL;
-    int nstr = 0;
+    size_t nstr = 0;
     const krb5_config_binding *b = NULL;
     const char *p;
 
diff --git a/source4/heimdal/lib/krb5/keytab_any.c b/source4/heimdal/lib/krb5/keytab_any.c
index d5ac4883db1..568af0ac69e 100644
--- a/source4/heimdal/lib/krb5/keytab_any.c
+++ b/source4/heimdal/lib/krb5/keytab_any.c
@@ -225,7 +225,7 @@ any_remove_entry(krb5_context context,
 {
     struct any_data *a = id->data;
     krb5_error_code ret;
-    int found = 0;
+    size_t found = 0;
     while(a != NULL) {
 	ret = krb5_kt_remove_entry(context, a->kt, entry);
 	if(ret == 0)
diff --git a/source4/heimdal/lib/roken/resolve.c b/source4/heimdal/lib/roken/resolve.c
index 0cfe0b0472a..b719aebaf0d 100644
--- a/source4/heimdal/lib/roken/resolve.c
+++ b/source4/heimdal/lib/roken/resolve.c
@@ -626,7 +626,7 @@ rk_dns_srv_order(struct rk_dns_reply *r)
 {
     struct rk_resource_record **srvs, **ss, **headp;
     struct rk_resource_record *rr;
-    int num_srv = 0;
+    size_t num_srv = 0;
 
 #if defined(HAVE_INITSTATE) && defined(HAVE_SETSTATE)
     int state[256 / sizeof(int)];
-- 
2.15.1


>From c239dc97eb909e13a37e81c253af5d72414723c4 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:35:11 +0100
Subject: [PATCH 02/41] s4:ntvfs: Fix size type in pvfs functions

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/ntvfs/posix/pvfs_resolve.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/source4/ntvfs/posix/pvfs_resolve.c b/source4/ntvfs/posix/pvfs_resolve.c
index 12fc0c1110b..cc3d72c2ed6 100644
--- a/source4/ntvfs/posix/pvfs_resolve.c
+++ b/source4/ntvfs/posix/pvfs_resolve.c
@@ -62,10 +62,10 @@ static NTSTATUS pvfs_case_search(struct pvfs_state *pvfs,
 				 unsigned int flags)
 {
 	/* break into a series of components */
-	int num_components;
+	size_t num_components;
 	char **components;
 	char *p, *partial_name;
-	int i;
+	size_t i;
 
 	/* break up the full name info pathname components */
 	num_components=2;
@@ -389,7 +389,7 @@ static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx,
 {
 	codepoint_t c;
 	size_t c_size, len;
-	int i, num_components, err_count;
+	size_t i, num_components, err_count;
 	char **components;
 	char *p, *s, *ret;
 
@@ -432,7 +432,7 @@ static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx,
 			err_count++;
 		}
 	}
-	if (err_count) {
+	if (err_count > 0) {
 		if (flags & PVFS_RESOLVE_WILDCARD) err_count--;
 
 		if (err_count==1) {
-- 
2.15.1


>From 3d8ff91a3de889cd1d05787444eff847048bef5f Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:38:21 +0100
Subject: [PATCH 03/41] s3:libads: Fix size types in kerberos functions

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/libads/kerberos.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c
index cfb09a704cb..82f118a021e 100644
--- a/source3/libads/kerberos.c
+++ b/source3/libads/kerberos.c
@@ -336,10 +336,10 @@ int kerberos_kinit_password(const char *principal,
 
 ************************************************************************/
 
-static void add_sockaddr_unique(struct sockaddr_storage *addrs, int *num_addrs,
+static void add_sockaddr_unique(struct sockaddr_storage *addrs, size_t *num_addrs,
 				const struct sockaddr_storage *addr)
 {
-	int i;
+	size_t i;
 
 	for (i=0; i<*num_addrs; i++) {
 		if (sockaddr_equal((const struct sockaddr *)&addrs[i],
@@ -382,12 +382,12 @@ static char *get_kdc_ip_string(char *mem_ctx,
 		const struct sockaddr_storage *pss)
 {
 	TALLOC_CTX *frame = talloc_stackframe();
-	int i;
+	size_t i;
 	struct ip_service *ip_srv_site = NULL;
 	struct ip_service *ip_srv_nonsite = NULL;
 	int count_site = 0;
 	int count_nonsite;
-	int num_dcs;
+	size_t num_dcs;
 	struct sockaddr_storage *dc_addrs;
 	struct tsocket_address **dc_addrs2 = NULL;
 	const struct tsocket_address * const *dc_addrs3 = NULL;
@@ -448,7 +448,7 @@ static char *get_kdc_ip_string(char *mem_ctx,
 				      struct tsocket_address *,
 				      num_dcs);
 
-	DEBUG(10, ("%d additional KDCs to test\n", num_dcs));
+	DBG_DEBUG("%zu additional KDCs to test\n", num_dcs);
 	if (num_dcs == 0) {
 		goto out;
 	}
-- 
2.15.1


>From 80e5b88adf1208f45ad7b3200122e187fb6a2089 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:40:00 +0100
Subject: [PATCH 04/41] s4:dns_server: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/dns_server/dns_server.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/dns_server/dns_server.c b/source4/dns_server/dns_server.c
index 9128c626cb9..5c6aca56207 100644
--- a/source4/dns_server/dns_server.c
+++ b/source4/dns_server/dns_server.c
@@ -687,7 +687,7 @@ static NTSTATUS dns_startup_interfaces(struct dns_server *dns,
 				       struct interface *ifaces,
 				       const struct model_ops *model_ops)
 {
-	int num_interfaces;
+	size_t num_interfaces;
 	TALLOC_CTX *tmp_ctx = talloc_new(dns);
 	NTSTATUS status;
 	int i;
@@ -704,7 +704,7 @@ static NTSTATUS dns_startup_interfaces(struct dns_server *dns,
 			NT_STATUS_NOT_OK_RETURN(status);
 		}
 	} else {
-		int num_binds = 0;
+		size_t num_binds = 0;
 		char **wcard;
 		wcard = iface_list_wildcard(tmp_ctx);
 		if (wcard == NULL) {
-- 
2.15.1


>From d3fee42567e56165fea14ffd348926a1ad43d59e Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:42:02 +0100
Subject: [PATCH 05/41] s4:rpc_server: Fix size types in dcerpc dnsserver

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/rpc_server/dnsserver/dcerpc_dnsserver.c | 4 ++--
 source4/rpc_server/dnsserver/dnsdata.c          | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/source4/rpc_server/dnsserver/dcerpc_dnsserver.c b/source4/rpc_server/dnsserver/dcerpc_dnsserver.c
index 120d4b9a3d7..5d3cb9e2a8e 100644
--- a/source4/rpc_server/dnsserver/dcerpc_dnsserver.c
+++ b/source4/rpc_server/dnsserver/dcerpc_dnsserver.c
@@ -1223,9 +1223,9 @@ static WERROR dnsserver_complex_operate_server(struct dnsserver_state *dsstate,
 {
 	int valid_operation = 0;
 	struct dnsserver_zone *z, **zlist;
-	int zcount;
+	size_t zcount;
 	bool found1, found2, found3, found4;
-	int i;
+	size_t i;
 
 	if (strcasecmp(operation, "QueryDwordProperty") == 0) {
 		if (typeid_in == DNSSRV_TYPEID_LPSTR) {
diff --git a/source4/rpc_server/dnsserver/dnsdata.c b/source4/rpc_server/dnsserver/dnsdata.c
index c3006433515..8080fa480b2 100644
--- a/source4/rpc_server/dnsserver/dnsdata.c
+++ b/source4/rpc_server/dnsserver/dnsdata.c
@@ -96,7 +96,7 @@ struct IP4_ARRAY *dns_addr_array_to_ip4_array(TALLOC_CTX *mem_ctx,
 					      struct DNS_ADDR_ARRAY *ip)
 {
 	struct IP4_ARRAY *ret;
-	int i, count, curr;
+	size_t i, count, curr;
 
 	if (ip == NULL) {
 		return NULL;
-- 
2.15.1


>From 50a82f20b936b1670e521f2f164b0cc638ee66ca Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:43:08 +0100
Subject: [PATCH 06/41] s4:ldap_server: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/ldap_server/ldap_server.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/ldap_server/ldap_server.c b/source4/ldap_server/ldap_server.c
index 5f7efe90bba..91e5d05b7fe 100644
--- a/source4/ldap_server/ldap_server.c
+++ b/source4/ldap_server/ldap_server.c
@@ -1178,8 +1178,8 @@ static void ldapsrv_task_init(struct task_server *task)
 		}
 	} else {
 		char **wcard;
-		int i;
-		int num_binds = 0;
+		size_t i;
+		size_t num_binds = 0;
 		wcard = iface_list_wildcard(task);
 		if (wcard == NULL) {
 			DEBUG(0,("No wildcard addresses available\n"));
-- 
2.15.1


>From 42c22be3d0feed128b11a8ef258494af12316357 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:43:58 +0100
Subject: [PATCH 07/41] s4:cldap_server: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/cldap_server/cldap_server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/cldap_server/cldap_server.c b/source4/cldap_server/cldap_server.c
index 3f845c7e240..a0cde776550 100644
--- a/source4/cldap_server/cldap_server.c
+++ b/source4/cldap_server/cldap_server.c
@@ -154,7 +154,7 @@ static NTSTATUS cldapd_startup_interfaces(struct cldapd_server *cldapd, struct l
 	/* if we are allowing incoming packets from any address, then
 	   we need to bind to the wildcard address */
 	if (!lpcfg_bind_interfaces_only(lp_ctx)) {
-		int num_binds = 0;
+		size_t num_binds = 0;
 		char **wcard = iface_list_wildcard(cldapd);
 		NT_STATUS_HAVE_NO_MEMORY(wcard);
 		for (i=0; wcard[i]; i++) {
-- 
2.15.1


>From 6a4c3dc954a3f0f630386ce4040987891c95d050 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:01:39 +0100
Subject: [PATCH 08/41] libcli:smb: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 libcli/smb/smbXcli_base.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c
index e9fdc1dc32a..fbf24416093 100644
--- a/libcli/smb/smbXcli_base.c
+++ b/libcli/smb/smbXcli_base.c
@@ -1914,7 +1914,7 @@ static NTSTATUS smb1cli_inbuf_parse_chain(uint8_t *buf, TALLOC_CTX *mem_ctx,
 					  struct iovec **piov, int *pnum_iov)
 {
 	struct iovec *iov;
-	int num_iov;
+	size_t num_iov;
 	size_t buflen;
 	size_t taken;
 	size_t remaining;
@@ -3470,7 +3470,8 @@ static NTSTATUS smb2cli_inbuf_parse_compound(struct smbXcli_conn *conn,
 					     uint8_t *buf,
 					     size_t buflen,
 					     TALLOC_CTX *mem_ctx,
-					     struct iovec **piov, int *pnum_iov)
+					     struct iovec **piov,
+					     size_t *pnum_iov)
 {
 	struct iovec *iov;
 	int num_iov = 0;
@@ -3656,7 +3657,7 @@ static NTSTATUS smb2cli_conn_dispatch_incoming(struct smbXcli_conn *conn,
 	struct tevent_req *req;
 	struct smbXcli_req_state *state = NULL;
 	struct iovec *iov = NULL;
-	int i, num_iov = 0;
+	size_t i, num_iov = 0;
 	NTSTATUS status;
 	bool defer = true;
 	struct smbXcli_session *last_session = NULL;
-- 
2.15.1


>From af8d7ac3591879c3ffa942cf7adbc2a2660bfbf2 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:03:37 +0100
Subject: [PATCH 09/41] s3:param: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/param/loadparm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 096c23f4fb3..45dd75a910a 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -1832,8 +1832,8 @@ static bool is_synonym_of(int parm1, int parm2, bool *inverse)
 
 static void show_parameter(int parmIndex)
 {
-	int enumIndex, flagIndex;
-	int parmIndex2;
+	size_t enumIndex, flagIndex;
+	size_t parmIndex2;
 	bool hadFlag;
 	bool hadSyn;
 	bool inverse;
-- 
2.15.1


>From 138f842796b4ead76d55776547efbede80cc6519 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:45:45 +0100
Subject: [PATCH 10/41] s4:utils: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/utils/oLschema2ldif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/utils/oLschema2ldif.c b/source4/utils/oLschema2ldif.c
index 108c2c8ab20..c46799d737a 100644
--- a/source4/utils/oLschema2ldif.c
+++ b/source4/utils/oLschema2ldif.c
@@ -68,7 +68,7 @@ struct ldb_dn *basedn;
 
 static int check_braces(const char *string)
 {
-	int b;
+	size_t b;
 	char *c;
 
 	b = 0;
-- 
2.15.1


>From 0e2cb481b5d2bfbfa04baa5dc9862774f085b2ea Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:48:00 +0100
Subject: [PATCH 11/41] s4:rpc_server: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/rpc_server/dcerpc_server.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c
index 24eaa65459e..a35560d6be8 100644
--- a/source4/rpc_server/dcerpc_server.c
+++ b/source4/rpc_server/dcerpc_server.c
@@ -3088,8 +3088,8 @@ static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx,
 		}
 	} else {
 		char **wcard;
-		int i;
-		int num_binds = 0;
+		size_t i;
+		size_t num_binds = 0;
 		wcard = iface_list_wildcard(dce_ctx);
 		NT_STATUS_HAVE_NO_MEMORY(wcard);
 		for (i=0; wcard[i]; i++) {
-- 
2.15.1


>From e45eb79b3e3d0b2bff1396e7ff1081b936d7ae7a Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:47:15 +0100
Subject: [PATCH 12/41] s4:torture: Fix size types in qsinfo test

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/torture/raw/qfsinfo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/source4/torture/raw/qfsinfo.c b/source4/torture/raw/qfsinfo.c
index 0f1717b9cb2..b9ce2465c20 100644
--- a/source4/torture/raw/qfsinfo.c
+++ b/source4/torture/raw/qfsinfo.c
@@ -124,9 +124,9 @@ static union smb_fsinfo *find(const char *name)
 bool torture_raw_qfsinfo(struct torture_context *torture, 
 			 struct smbcli_state *cli)
 {
-	int i;
+	size_t i;
 	bool ret = true;
-	int count;
+	size_t count;
 	union smb_fsinfo *s1, *s2;	
 
 	/* scan all the levels, pulling the results */
@@ -152,7 +152,7 @@ bool torture_raw_qfsinfo(struct torture_context *torture,
 	}
 
 	if (count != 0) {
-		torture_comment(torture, "%d levels failed\n", count);
+		torture_comment(torture, "%zu levels failed\n", count);
 		torture_assert(torture, count > 13, "too many level failures - giving up");
 	}
 
-- 
2.15.1


>From 9a90954d82f9f43c3135c752938655ec3db33fdd Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:49:00 +0100
Subject: [PATCH 13/41] s4:torture: Fix size types in qfileinfo test

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/torture/raw/qfileinfo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/source4/torture/raw/qfileinfo.c b/source4/torture/raw/qfileinfo.c
index 0c5daa3ccc3..dd529250969 100644
--- a/source4/torture/raw/qfileinfo.c
+++ b/source4/torture/raw/qfileinfo.c
@@ -229,9 +229,9 @@ static bool torture_raw_qfileinfo_internals(struct torture_context *torture,
 					    int fnum, const char *fname,
 					    bool is_ipc)
 {
-	int i;
+	size_t i;
 	bool ret = true;
-	int count;
+	size_t count;
 	union smb_fileinfo *s1, *s2;	
 	NTTIME correct_time;
 	uint64_t correct_size;
@@ -333,7 +333,7 @@ static bool torture_raw_qfileinfo_internals(struct torture_context *torture,
 
 	if (count != 0) {
 		ret = false;
-		printf("%d levels failed\n", count);
+		printf("%zu levels failed\n", count);
 		if (count > 35) {
 			torture_fail(torture, "too many level failures - giving up");
 		}
-- 
2.15.1


>From 880c01337d76ed2345aafb23ab7f0204f5633a07 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:50:33 +0100
Subject: [PATCH 14/41] s3:torture: Fix size types in spoolss test

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/torture/rpc/spoolss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/torture/rpc/spoolss.c b/source4/torture/rpc/spoolss.c
index 31b9525ee62..380137b3dd3 100644
--- a/source4/torture/rpc/spoolss.c
+++ b/source4/torture/rpc/spoolss.c
@@ -5628,7 +5628,7 @@ static bool test_SetPrinterDataEx_matrix(struct torture_context *tctx,
 		REG_BINARY
 	};
 	const char *str = "abcdefghi";
-	int t, s;
+	size_t t, s;
 
 	for (t=0; t < ARRAY_SIZE(types); t++) {
 	for (s=0; s < strlen(str); s++) {
-- 
2.15.1


>From 8d960f6923fa23568a3e01dae2b959d3deb55df0 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:52:39 +0100
Subject: [PATCH 15/41] s3:libsmb: Fix size types in nmblib

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/libsmb/nmblib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c
index 8feb029b05e..a2d561d6c7d 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -176,11 +176,11 @@ static bool handle_name_ptrs(unsigned char *ubuf,int *offset,int length,
 
 static int parse_nmb_name(char *inbuf,int ofs,int length, struct nmb_name *name)
 {
-	int m,n=0;
+	size_t m,n=0;
 	unsigned char *ubuf = (unsigned char *)inbuf;
 	int ret = 0;
 	bool got_pointer=False;
-	int loop_count=0;
+	size_t loop_count=0;
 	int offset = ofs;
 
 	if (length - offset < 2)
@@ -483,7 +483,7 @@ static int put_compressed_name_ptr(unsigned char *buf,
 
 static bool parse_dgram(char *inbuf,int length,struct dgram_packet *dgram)
 {
-	int offset;
+	size_t offset;
 	int flags;
 
 	memset((char *)dgram,'\0',sizeof(*dgram));
-- 
2.15.1


>From c4c6004e1bb8fe8407f70d32d8a294dfb7403c94 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:54:12 +0100
Subject: [PATCH 16/41] s4:torture: Fix size types in nss tests

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/torture/local/nss_tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/torture/local/nss_tests.c b/source4/torture/local/nss_tests.c
index 2cd61225ab8..cc02047d565 100644
--- a/source4/torture/local/nss_tests.c
+++ b/source4/torture/local/nss_tests.c
@@ -899,7 +899,7 @@ static bool test_reentrant_enumeration_crosschecks(struct torture_context *tctx)
 
 static bool test_passwd_duplicates(struct torture_context *tctx)
 {
-	int i, d;
+	size_t i, d;
 	struct passwd *pwd;
 	size_t num_pwd;
 	int duplicates = 0;
@@ -934,7 +934,7 @@ static bool test_passwd_duplicates(struct torture_context *tctx)
 
 static bool test_group_duplicates(struct torture_context *tctx)
 {
-	int i, d;
+	size_t i, d;
 	struct group *grp;
 	size_t num_grp;
 	int duplicates = 0;
-- 
2.15.1


>From 9bdfa19465c9775d32c91c087d956d80e1919e9a Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:55:34 +0100
Subject: [PATCH 17/41] s4:client: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/client/client.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/source4/client/client.c b/source4/client/client.c
index e04aa25d69b..f73d9f99d20 100644
--- a/source4/client/client.c
+++ b/source4/client/client.c
@@ -2849,10 +2849,10 @@ static struct
   ******************************************************************/
 static int process_tok(const char *tok)
 {
-	int i = 0, matches = 0;
-	int cmd=0;
-	int tok_len = strlen(tok);
-	
+	size_t i = 0, matches = 0;
+	size_t cmd=0;
+	size_t tok_len = strlen(tok);
+
 	while (commands[i].fn != NULL) {
 		if (strequal(commands[i].name,tok)) {
 			matches = 1;
-- 
2.15.1


>From eaceb9ceac23396575634beedaef9546de47232c Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:47:18 +0100
Subject: [PATCH 18/41] s3:client: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/client/client.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/source3/client/client.c b/source3/client/client.c
index ad10a5381dd..49d027ad4ac 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -5607,9 +5607,9 @@ static struct {
 
 static int process_tok(char *tok)
 {
-	int i = 0, matches = 0;
-	int cmd=0;
-	int tok_len = strlen(tok);
+	size_t i = 0, matches = 0;
+	size_t cmd=0;
+	size_t tok_len = strlen(tok);
 
 	while (commands[i].fn != NULL) {
 		if (strequal(commands[i].name,tok)) {
-- 
2.15.1


>From 5f23c41a4137c3edb3b158988c3433c1221816f6 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:57:05 +0100
Subject: [PATCH 19/41] s3:avahi: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/smbd/avahi_register.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/smbd/avahi_register.c b/source3/smbd/avahi_register.c
index 50462b5c610..6c87669ba36 100644
--- a/source3/smbd/avahi_register.c
+++ b/source3/smbd/avahi_register.c
@@ -108,7 +108,7 @@ static void avahi_client_callback(AvahiClient *c, AvahiClientState status,
 	case AVAHI_CLIENT_S_RUNNING: {
 		int snum;
 		int num_services = lp_numservices();
-		int dk = 0;
+		size_t dk = 0;
 		AvahiStringList *adisk = NULL;
 		AvahiStringList *adisk2 = NULL;
 		const char *hostname = NULL;
@@ -154,7 +154,7 @@ static void avahi_client_callback(AvahiClient *c, AvahiClientState status,
 			    lp_parm_bool(snum, "fruit", "time machine", false))
 			{
 				adisk2 = avahi_string_list_add_printf(
-					    adisk, "dk%d=adVN=%s,adVF=0x82",
+					    adisk, "dk%zu=adVN=%s,adVF=0x82",
 					    dk++, lp_const_servicename(snum));
 				if (adisk2 == NULL) {
 					DBG_DEBUG("avahi_string_list_add_printf"
-- 
2.15.1


>From a882112db8d996d6998a8f0766c73361f9419a5b Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:58:38 +0100
Subject: [PATCH 20/41] s3:printing: Fix size type in printing_db

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/printing/printing_db.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/printing/printing_db.c b/source3/printing/printing_db.c
index 1a129eaad3b..7465195b771 100644
--- a/source3/printing/printing_db.c
+++ b/source3/printing/printing_db.c
@@ -35,7 +35,7 @@ static struct tdb_print_db *print_db_head;
 struct tdb_print_db *get_print_db_byname(const char *printername)
 {
 	struct tdb_print_db *p = NULL, *last_entry = NULL;
-	int num_open = 0;
+	size_t num_open = 0;
 	char *printdb_path = NULL;
 	bool done_become_root = False;
 	char *print_cache_path;
-- 
2.15.1


>From d33ad1ec081e1ca75af1770e64f101fd8a8b6188 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:27:41 +0100
Subject: [PATCH 21/41] s3:winbindd: Fix size types in idmap_tdb_common

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/winbindd/idmap_tdb_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/winbindd/idmap_tdb_common.c b/source3/winbindd/idmap_tdb_common.c
index e873b60bd8f..48d87bb16cf 100644
--- a/source3/winbindd/idmap_tdb_common.c
+++ b/source3/winbindd/idmap_tdb_common.c
@@ -307,7 +307,7 @@ NTSTATUS idmap_tdb_common_unixids_to_sids(struct idmap_domain * dom,
 					  struct id_map ** ids)
 {
 	NTSTATUS ret;
-	int i, num_mapped = 0;
+	size_t i, num_mapped = 0;
 	struct idmap_tdb_common_context *ctx;
 
 	NTSTATUS(*unixid_to_sid_fn) (struct idmap_domain * dom,
@@ -543,7 +543,7 @@ static NTSTATUS idmap_tdb_common_sids_to_unixids_action(struct db_context *db,
 							void *private_data)
 {
 	struct idmap_tdb_common_sids_to_unixids_context *state = private_data;
-	int i, num_mapped = 0;
+	size_t i, num_mapped = 0;
 	NTSTATUS ret = NT_STATUS_OK;
 
 	DEBUG(10, ("idmap_tdb_common_sids_to_unixids: "
-- 
2.15.1


>From da99d3488f864bf22042db6be172ead8c710b8bd Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:39:07 +0100
Subject: [PATCH 22/41] s3:vfs_nettalk: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/modules/vfs_netatalk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/modules/vfs_netatalk.c b/source3/modules/vfs_netatalk.c
index 206c3b69060..3085cf4c7c9 100644
--- a/source3/modules/vfs_netatalk.c
+++ b/source3/modules/vfs_netatalk.c
@@ -118,7 +118,7 @@ static int atalk_unlink_file(const char *path)
 
 static void atalk_add_to_list(name_compare_entry **list)
 {
-	int i, count = 0;
+	size_t i, count = 0;
 	name_compare_entry *new_list = 0;
 	name_compare_entry *cur_list = 0;
 
-- 
2.15.1


>From c6d4afc19088de9bdf734e21318a5fcbd63c8b6f Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:42:44 +0100
Subject: [PATCH 23/41] s3:rpc_server: Fix size types in srvsvc

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
index 2ff8e64fccc..85a2fc35a5b 100644
--- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
@@ -547,13 +547,13 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 				      uint32_t *total_entries,
 				      bool all_shares)
 {
-	int num_entries = 0;
-	int alloc_entries = 0;
+	uint32_t num_entries = 0;
+	uint32_t alloc_entries = 0;
 	int num_services = 0;
 	int snum;
 	TALLOC_CTX *ctx = p->mem_ctx;
-	int i = 0;
-	int valid_share_count = 0;
+	uint32_t i = 0;
+	uint32_t valid_share_count = 0;
 	bool *allowed = 0;
 	union srvsvc_NetShareCtr ctr;
 	uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
-- 
2.15.1


>From 160777125d89832cbea79f5ac66d05d0c9c77f10 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 19:47:04 +0100
Subject: [PATCH 24/41] s3:utils: Fix size type in log2pcaphex

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/utils/log2pcaphex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c
index f31efa10df8..5310982bed3 100644
--- a/source3/utils/log2pcaphex.c
+++ b/source3/utils/log2pcaphex.c
@@ -305,7 +305,7 @@ int main(int argc, const char **argv)
 	long data_offset = 0;
 	long data_length;
 	long data_bytes_read = 0;
-	int in_packet = 0;
+	size_t in_packet = 0;
 	struct poptOption long_options[] = {
 		POPT_AUTOHELP
 		{ "quiet", 'q', POPT_ARG_NONE, &quiet, 0, "Be quiet, don't output warnings" },
-- 
2.15.1


>From fd45af43e927986af07f2c2abe007209840007f7 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 19:47:50 +0100
Subject: [PATCH 25/41] s3:nmbd: Fix size type in nmbd_browsesync.c

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/nmbd/nmbd_browsesync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c
index b1517f89c9f..6f90e613478 100644
--- a/source3/nmbd/nmbd_browsesync.c
+++ b/source3/nmbd/nmbd_browsesync.c
@@ -629,7 +629,7 @@ void sync_all_dmbs(time_t t)
 {
 	static time_t lastrun = 0;
 	struct work_record *work;
-	int count=0;
+	size_t count=0;
 
 	/* Only do this if we are using a WINS server. */
 	if(we_are_a_wins_client() == False)
-- 
2.15.1


>From 30d7937198c89fffa7c4e22fb5e0a227589b99fd Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 20:07:08 +0100
Subject: [PATCH 26/41] s3:modules: Fix size type in getdate

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/modules/getdate.c | 2 +-
 source3/modules/getdate.y | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/modules/getdate.c b/source3/modules/getdate.c
index 6ed994649c4..8840d85cb7a 100644
--- a/source3/modules/getdate.c
+++ b/source3/modules/getdate.c
@@ -2491,7 +2491,7 @@ static int
 yylex (YYSTYPE *lvalp, parser_control *pc)
 {
   unsigned char c;
-  int count;
+  size_t count;
 
   for (;;)
     {
diff --git a/source3/modules/getdate.y b/source3/modules/getdate.y
index 1ddcda4fca7..2e49f15b87f 100644
--- a/source3/modules/getdate.y
+++ b/source3/modules/getdate.y
@@ -790,7 +790,7 @@ static int
 yylex (YYSTYPE *lvalp, parser_control *pc)
 {
   unsigned char c;
-  int count;
+  size_t count;
 
   for (;;)
     {
-- 
2.15.1


>From fffa2c2002f11659d09a7d593f29621df7548f53 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:48:45 +0100
Subject: [PATCH 27/41] s3:passdb: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/passdb/pdb_ldap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c
index c495448dcc5..bf9377c88d3 100644
--- a/source3/passdb/pdb_ldap.c
+++ b/source3/passdb/pdb_ldap.c
@@ -4103,7 +4103,8 @@ static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods,
 	LDAPMessage *msg = NULL;
 	LDAPMessage *entry;
 	char *allsids = NULL;
-	int i, rc, num_mapped;
+	size_t i, num_mapped;
+	int rc;
 	NTSTATUS result = NT_STATUS_NO_MEMORY;
 	TALLOC_CTX *mem_ctx;
 	LDAP *ld;
-- 
2.15.1


>From 908fdf773aac337fb2fe3ff7831877469d86c3a4 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:50:20 +0100
Subject: [PATCH 28/41] s3:rpc_server: Fix size types in spoolss

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/rpc_server/spoolss/srv_spoolss_nt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c
index f0226ba9441..fceb08fba38 100644
--- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
+++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
@@ -1085,13 +1085,13 @@ static int build_notify2_messages(TALLOC_CTX *mem_ctx,
 				  SPOOLSS_NOTIFY_MSG *messages,
 				  uint32_t num_msgs,
 				  struct spoolss_Notify **_notifies,
-				  int *_count)
+				  size_t *_count)
 {
 	struct spoolss_Notify *notifies;
 	SPOOLSS_NOTIFY_MSG *msg;
-	int count = 0;
+	size_t count = 0;
 	uint32_t id;
-	int i;
+	uint32_t i;
 
 	notifies = talloc_zero_array(mem_ctx,
 				     struct spoolss_Notify, num_msgs);
@@ -1184,7 +1184,7 @@ static int send_notify2_printer(TALLOC_CTX *mem_ctx,
 				SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
 {
 	struct spoolss_Notify *notifies;
-	int count = 0;
+	size_t count = 0;
 	union spoolss_ReplyPrinterInfo info;
 	struct spoolss_NotifyInfo info0;
 	uint32_t reply_result;
-- 
2.15.1


>From 5cb9f3beeb40f737ec5c07a375bd15c642790abc Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 19:21:38 +0100
Subject: [PATCH 29/41] s3:rpcclient: Fix size types

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/rpcclient/rpcclient.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index c1039ed84c5..c364d504045 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -73,7 +73,7 @@ static char **completion_fn(const char *text, int start, int end)
 {
 #define MAX_COMPLETIONS 1000
 	char **matches;
-	int i, count=0;
+	size_t i, count=0;
 	struct cmd_list *commands = cmd_list;
 
 #if 0	/* JERRY */
-- 
2.15.1


>From 40e60634235ad9164957b2d904a41636ac644ff0 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Fri, 8 Dec 2017 10:03:00 +0100
Subject: [PATCH 30/41] ldb: Fix size types in ldb_ldif functions

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 lib/ldb/common/ldb_ldif.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/ldb/common/ldb_ldif.c b/lib/ldb/common/ldb_ldif.c
index b90d27eea59..e23b568707d 100644
--- a/lib/ldb/common/ldb_ldif.c
+++ b/lib/ldb/common/ldb_ldif.c
@@ -216,7 +216,8 @@ static int fold_string(int (*fprintf_fn)(void *, const char *, ...), void *priva
 			const char *buf, size_t length, int start_pos)
 {
 	size_t i;
-	int total=0, ret;
+	size_t total = 0;
+	int ret;
 
 	for (i=0;i<length;i++) {
 		ret = fprintf_fn(private_data, "%c", buf[i]);
@@ -280,7 +281,8 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
 {
 	TALLOC_CTX *mem_ctx;
 	unsigned int i, j;
-	int total=0, ret;
+	size_t total = 0;
+	int ret;
 	char *p;
 	const struct ldb_message *msg;
 	const char * const * secret_attributes = ldb_get_opaque(ldb, LDB_SECRET_ATTRIBUTE_LIST_OPAQUE);
-- 
2.15.1


>From c9aee05a38a0e7058b9ae3d3249060e3bdc568b1 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 15:54:13 +0100
Subject: [PATCH 31/41] lib:socket: Return early if we have only one interface

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 lib/socket/interfaces.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/socket/interfaces.c b/lib/socket/interfaces.c
index 6409275d7bc..168bff501c2 100644
--- a/lib/socket/interfaces.c
+++ b/lib/socket/interfaces.c
@@ -367,7 +367,10 @@ int get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces)
 	int total, i, j;
 
 	total = _get_interfaces(mem_ctx, &ifaces);
-	if (total <= 0) return total;
+	/* If we have an error, no interface or just one we can leave */
+	if (total <= 1) {
+		return total;
+	}
 
 	/* now we need to remove duplicates */
 	TYPESAFE_QSORT(ifaces, total, iface_comp);
-- 
2.15.1


>From 41cf21286acab9c5dee0ff20ba9ade7f86daa8d1 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 16:40:51 +0100
Subject: [PATCH 32/41] lib:param: Fix P_LIST case in set_variable_helper()

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 lib/param/loadparm.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 7854f57a158..986e115b385 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -1670,20 +1670,21 @@ static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr
 				break;
 			}
 
+			if (*(const char ***)parm_ptr == NULL) {
+				*(char ***)parm_ptr = new_list;
+				break;
+			}
+
 			for (i=0; new_list[i]; i++) {
-				if (*(const char ***)parm_ptr != NULL &&
-				    new_list[i][0] == '+' &&
-				    new_list[i][1])
-				{
+				if (new_list[i][0] == '+' &&
+				    new_list[i][1] != '\0') {
 					if (!str_list_check(*(const char ***)parm_ptr,
 							    &new_list[i][1])) {
 						*(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
 											 &new_list[i][1]);
 					}
-				} else if (*(const char ***)parm_ptr != NULL &&
-					   new_list[i][0] == '-' &&
-					   new_list[i][1])
-				{
+				} else if (new_list[i][0] == '-' &&
+					   new_list[i][1] != '\0') {
 					str_list_remove(*(const char ***)parm_ptr,
 							&new_list[i][1]);
 				} else {
@@ -1692,8 +1693,6 @@ static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr
 							  pszParmName, pszParmValue));
 						return false;
 					}
-					*(char ***)parm_ptr = new_list;
-					break;
 				}
 			}
 			break;
-- 
2.15.1


>From 5000367c12bcaf8f3d6a1eb6e611866a6e04393b Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 26 Oct 2017 09:47:57 +0200
Subject: [PATCH 33/41] util: Add sanity check for count in
 ms_fnmatch_protocol()

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 lib/util/ms_fnmatch.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/util/ms_fnmatch.c b/lib/util/ms_fnmatch.c
index c0f61ab04e7..4068b3cf1be 100644
--- a/lib/util/ms_fnmatch.c
+++ b/lib/util/ms_fnmatch.c
@@ -164,7 +164,8 @@ static int ms_fnmatch_core(const char *p, const char *n,
 int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol,
 			bool is_case_sensitive)
 {
-	int ret, count, i;
+	int ret = -1;
+	size_t count, i;
 
 	if (strcmp(string, "..") == 0) {
 		string = ".";
@@ -209,7 +210,7 @@ int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol,
 		if (pattern[i] == '*' || pattern[i] == '<') count++;
 	}
 
-	{
+	if (count > 0) {
 		struct max_n max_n[count];
 
 		memset(max_n, 0, sizeof(struct max_n) * count);
-- 
2.15.1


>From 67e93eeee2c4a56b473e3f664f997fad6e973ab6 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 16:58:25 +0100
Subject: [PATCH 34/41] s3:lib: Fix sanity checks in ms_fnmatch()

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/lib/ms_fnmatch.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c
index 9763afefe76..fb58ec26fd2 100644
--- a/source3/lib/ms_fnmatch.c
+++ b/source3/lib/ms_fnmatch.c
@@ -150,7 +150,8 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
 {
 	smb_ucs2_t *p = NULL;
 	smb_ucs2_t *s = NULL;
-	int ret, count, i;
+	int ret;
+	size_t count, i;
 	struct max_n *max_n = NULL;
 	struct max_n *max_n_free = NULL;
 	struct max_n one_max_n;
@@ -203,7 +204,7 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
 		if (p[i] == UCS2_CHAR('*') || p[i] == UCS2_CHAR('<')) count++;
 	}
 
-	if (count != 0) {
+	if (count > 0) {
 		if (count == 1) {
 			/*
 			 * We're doing this a LOT, so save the effort to allocate
-- 
2.15.1


>From 6fa705ed1932af8e3e7190503ebaa9436917e395 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 17:32:36 +0100
Subject: [PATCH 35/41] s4:dsdb: Fix integer operations

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/dsdb/samdb/ldb_modules/operational.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/source4/dsdb/samdb/ldb_modules/operational.c b/source4/dsdb/samdb/ldb_modules/operational.c
index 08a8454eca6..576cf861574 100644
--- a/source4/dsdb/samdb/ldb_modules/operational.c
+++ b/source4/dsdb/samdb/ldb_modules/operational.c
@@ -699,7 +699,7 @@ static NTTIME get_msds_user_password_expiry_time_computed(struct ldb_module *mod
 		return 0x7FFFFFFFFFFFFFFFULL;
 	}
 
-	if (pwdLastSet >= 0x7FFFFFFFFFFFFFFFULL) {
+	if (pwdLastSet >= 0x7FFFFFFFFFFFFFFFLL) {
 		/*
 		 * Somethings wrong with the clock...
 		 */
@@ -725,7 +725,7 @@ static NTTIME get_msds_user_password_expiry_time_computed(struct ldb_module *mod
 		return 0x7FFFFFFFFFFFFFFFULL;
 	}
 
-	if (maxPwdAge == -0x8000000000000000ULL) {
+	if (maxPwdAge == -0x8000000000000000LL) {
 		return 0x7FFFFFFFFFFFFFFFULL;
 	}
 
@@ -740,7 +740,7 @@ static NTTIME get_msds_user_password_expiry_time_computed(struct ldb_module *mod
 	 * =
 	 * 0xFFFFFFFFFFFFFFFFULL
 	 */
-	ret = pwdLastSet - maxPwdAge;
+	ret = (NTTIME)pwdLastSet - (NTTIME)maxPwdAge;
 	if (ret >= 0x7FFFFFFFFFFFFFFFULL) {
 		return 0x7FFFFFFFFFFFFFFFULL;
 	}
-- 
2.15.1


>From 14ead23b0a47887386f225aecb52e7688d045c89 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 15:24:59 +0100
Subject: [PATCH 36/41] s3:nmbd: Fix possible integer overflow

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/nmbd/nmbd_sendannounce.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c
index 1d557c45bbd..44d67e7ca84 100644
--- a/source3/nmbd/nmbd_sendannounce.c
+++ b/source3/nmbd/nmbd_sendannounce.c
@@ -288,8 +288,10 @@ void announce_my_server_names(time_t t)
 			}
 
 			/* Announce every minute at first then progress to every 12 mins */
-			if ((t - work->lastannounce_time) < work->announce_interval)
+			if (t > work->lastannounce_time &&
+			    (t - work->lastannounce_time) < work->announce_interval) {
 				continue;
+			}
 
 			if (work->announce_interval < (CHECK_TIME_MAX_HOST_ANNCE * 60))
 				work->announce_interval += 60;
-- 
2.15.1


>From 4b078effddcacdf591c1c8ddea66ab5aebb7bed7 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:24:18 +0100
Subject: [PATCH 37/41] s3:locking: Fix integer overflow check in
 posix_lock_in_range()

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/locking/posix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/locking/posix.c b/source3/locking/posix.c
index ff794282114..0b627aaa3e5 100644
--- a/source3/locking/posix.c
+++ b/source3/locking/posix.c
@@ -145,7 +145,8 @@ static bool posix_lock_in_range(off_t *offset_out, off_t *count_out,
 	 * Truncate count to end at max lock offset.
 	 */
 
-	if (offset + count < 0 || offset + count > max_positive_lock_offset) {
+	if (offset > INT64_MAX - count ||
+	    offset + count > max_positive_lock_offset) {
 		count = max_positive_lock_offset - offset;
 	}
 
-- 
2.15.1


>From e5523f083d1999f599a62df955c63503ea51550b Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:01:45 +0100
Subject: [PATCH 38/41] s3:printing: Fix size check in get_file_version()

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/printing/nt_printing.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index 2e500f18c7d..00c737d2fd4 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -485,7 +485,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32_t *major, uint
 				/* Potential match data crosses buf boundry, move it to beginning
 				 * of buf, and fill the buf with as much as it will hold. */
 				if (i>byte_count-VS_VERSION_INFO_SIZE) {
-					int bc;
+					ssize_t bc;
 
 					memcpy(buf, &buf[i], byte_count-i);
 					if ((bc = vfs_read_data(fsp, &buf[byte_count-i], VS_NE_BUF_SIZE-
@@ -496,8 +496,10 @@ static int get_file_version(files_struct *fsp, char *fname,uint32_t *major, uint
 						goto error_exit;
 					}
 
+					if (byte_count - i < VS_VERSION_INFO_SIZE) {
+						break;
+					}
 					byte_count = bc + (byte_count - i);
-					if (byte_count<VS_VERSION_INFO_SIZE) break;
 
 					i = 0;
 				}
-- 
2.15.1


>From 42567c6d2da3b48c98fa66aa0f8b1779943bb1e6 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 18:44:59 +0100
Subject: [PATCH 39/41] s3:vfs_preopen: Change to a do-while loop and fix the
 check

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/modules/vfs_preopen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/modules/vfs_preopen.c b/source3/modules/vfs_preopen.c
index aac00c7be95..b6a63d35b1e 100644
--- a/source3/modules/vfs_preopen.c
+++ b/source3/modules/vfs_preopen.c
@@ -156,7 +156,7 @@ static bool preopen_helper_open_one(int sock_fd, char **pnamebuf,
 
 	nread = 0;
 
-	while ((nread == 0) || (namebuf[nread-1] != '\0')) {
+	do {
 		ssize_t thistime;
 
 		thistime = read(sock_fd, namebuf + nread,
@@ -176,7 +176,7 @@ static bool preopen_helper_open_one(int sock_fd, char **pnamebuf,
 			}
 			*pnamebuf = namebuf;
 		}
-	}
+	} while (namebuf[nread - 1] != '\0');
 
 	fd = open(namebuf, O_RDONLY);
 	if (fd == -1) {
-- 
2.15.1


>From dd89fa55941359faa14d4caaf89ed72c3374851b Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 19:46:21 +0100
Subject: [PATCH 40/41] s3:registry: Fix size types and length calculations

This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/registry/reg_format.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/source3/registry/reg_format.c b/source3/registry/reg_format.c
index 15f63c7c06a..36ccb626194 100644
--- a/source3/registry/reg_format.c
+++ b/source3/registry/reg_format.c
@@ -54,16 +54,17 @@ static void cstr_unescape(char* val)
  * @see srprs_val_name
  */
 static int cbuf_print_value_assign(cbuf* ost, const char* name) {
-	int ret, n;
+	size_t ret = 0;
+	int n;
 	if (*name == '\0') {
-		ret = cbuf_putc(ost, '@');
+		n = cbuf_putc(ost, '@');
 	} else {
-		ret = cbuf_print_quoted_string(ost, name);
+		n = cbuf_print_quoted_string(ost, name);
 	}
-
-	if (ret<0) {
-		return ret;
+	if (n < 0) {
+		return n;
 	}
+	ret += n;
 
 	n = cbuf_putc(ost, '=');
 	if (n < 0) {
@@ -120,7 +121,8 @@ cbuf_print_hive(cbuf* ost, const char* hive, int len, const struct fmt_key* fmt)
 static int
 cbuf_print_keyname(cbuf* ost, const char* key[], int n, const struct fmt_key* fmt)
 {
-	int r, ret=0;
+	int r;
+	size_t ret = 0;
 	size_t pos = cbuf_getpos(ost);
 	bool hive = true;
 
-- 
2.15.1


>From 0ef057b35638f629657269199923299968bd6fb1 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 7 Dec 2017 15:27:44 +0100
Subject: [PATCH 41/41] wafsamba: Add -Wstrict-overflow

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 buildtools/wafsamba/samba_autoconf.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index 7940a7d4fe8..f91329e0612 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -709,6 +709,8 @@ def SAMBA_CONFIG_H(conf, path=None):
                         testflags=True)
         conf.ADD_CFLAGS('-Werror=uninitialized -Wuninitialized',
                         testflags=True)
+        conf.ADD_CFLAGS('-Werror=strict-overflow -Wstrict-overflow=2',
+                        testflags=True)
 
         conf.ADD_CFLAGS('-Wformat=2 -Wno-format-y2k', testflags=True)
         conf.ADD_CFLAGS('-Wno-format-zero-length', testflags=True)
-- 
2.15.1



More information about the samba-technical mailing list