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

Andreas Schneider asn at samba.org
Tue Dec 12 07:34:19 UTC 2017


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.

Volker only pushed one patch from the patchset, attached is a rebased new 
patchset.


Review much appreciated.
 
 
Thanks,
 
 
 	Andreas


-- 
Andreas Schneider                   GPG-ID: CC014E3D
Samba Team                             asn at samba.org
www.samba.org
-------------- next part --------------
>From 9ade0d742bf700aeefa9a10a1f78275aa3f53702 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 a659d2603317818e2ea8d18b9d87a666a6f33994 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 16d75703159f9a5fd579298ccb422051c4a0c3d3 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 07a9080449a21a1ad46794ca63fe92213b7a7b2c 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 cd293b82522..b7f41b5c42f 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 e5e61349fe86e385b03c1a9d732efa3a537b02e0 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 d17bc42b0ea3f8bb01afdcf5eb111689a584e28b 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 7de7513be5671ac2586b0336ea9a8f5fcd935f1e 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 0f412b854c34bf42c21035a8885ff3611062d431 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 6335ce0c121..4df39c5d6da 100644
--- a/libcli/smb/smbXcli_base.c
+++ b/libcli/smb/smbXcli_base.c
@@ -1901,7 +1901,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;
@@ -3457,7 +3457,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;
@@ -3643,7 +3644,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 bb1c6b64b15837a00831e51eb292353c583891e9 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 01c022e2889..7213ffb24ac 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -1833,8 +1833,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 6871ab9c6d7b66b25eb63f622da5f089d9c4e92a 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 208f1f6eaf6adf0691005f572ab4317cf10f48da 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 c8bd244d58d908919786a496f3f940a07723337f 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 9fede8c0056d7241634a081c563707d769123979 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 ce694bc0dd7ed09a3e61d4ae586196272e159925 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 5972550f52e12234ba0d78bd93982fa9a32e0b2f 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 4c38e752f0598895556a8f3d5b8b7e94312b5f4d 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 af6c0e59523f962fabecabf8a2fe85b23c01bd79 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 0d2481b6460b28f7a7886519c2e2e3b7769540ee 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 eee4f2608faa956108575a42047a407e1efc60e8 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 fe696ed9a64c08f1b640576930a4c04477cc1549 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 8082e1a1e0425a62eee65a3790dcb67116b79f20 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 e23a297dc105a7f656edcc54a7f7b3c23bb36334 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 16c129de995..4ebb945cd1b 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 6af7bea0f6fee6a657338416ca26e6b816c77c75 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 eb6d83e164c3a5e63ca2873cb57c21ce97c85d57 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 433a0f09ca9012ed3fb481b336896da210f98e6d 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 b6de41d85ba3bc67a12ea5671674c87660552037 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 aa630fa2db999a42e5f5b4af463898e3ff313fcb 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 93f44a7bf03268088a38dc5a27e23eec7564cd34 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 203db3e3bc4a528881570e8f107313d00f2148c6 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 0d1cc31e4cdfae69e94b1f213ac07d494744f182 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 74a52bfc78b57c4b6bc853a91541d54e7ef6e17f 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 8a98b325bc0e60604edc2c699f9e472f5bb549e4 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 73b7901d7f6..43a5cf16ef9 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 80c2a7dd4af34484cf37e77438467529b8b8003a 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 0b98656ea901ff19a30be257604f41c6bb740348 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 89c8b942aa59c715e948e6622ab5cb5956547571 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 a6b8b903dbeff15e232e4101324eba032d6a4b21 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 735fcb8a7a9739b0c8c77cc10f9ae352e7b78d39 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 ee80adfa23a37f90c7e8cad5a08651590c0f24f8 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 93f2ac356d2d6436a9fd564667fe8ef226240d49 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 18b01e6c05e..f4c4ba65cca 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 8681751b076e17d72ede6e6aee5861182acaf09d 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 6424e21933c3efe159e305ecf4b5a378a5762585 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