Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Dec 2017 15:41:33 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r326853 - head/sbin/dhclient
Message-ID:  <201712141541.vBEFfXmb038550@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Thu Dec 14 15:41:32 2017
New Revision: 326853
URL: https://svnweb.freebsd.org/changeset/base/326853

Log:
  dhclient(8): raise WARNS to 3
  
  Mostly had to fix a lot of signed/unsigned comparison warnings
  
  MFC after:	3 weeks
  Sponsored by:	Spectra Logic Corp

Modified:
  head/sbin/dhclient/Makefile
  head/sbin/dhclient/clparse.c
  head/sbin/dhclient/conflex.c
  head/sbin/dhclient/dhclient.c
  head/sbin/dhclient/dhcpd.h
  head/sbin/dhclient/inet.c
  head/sbin/dhclient/options.c
  head/sbin/dhclient/packet.c
  head/sbin/dhclient/parse.c
  head/sbin/dhclient/privsep.c
  head/sbin/dhclient/tree.c

Modified: head/sbin/dhclient/Makefile
==============================================================================
--- head/sbin/dhclient/Makefile	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/Makefile	Thu Dec 14 15:41:32 2017	(r326853)
@@ -50,7 +50,7 @@ LIBADD+=        cap_syslog
 CFLAGS+=-DWITH_CASPER
 .endif
 
-WARNS?=	2
+WARNS?=	3
 
 HAS_TESTS=
 SUBDIR.${MK_TESTS}+= tests

Modified: head/sbin/dhclient/clparse.c
==============================================================================
--- head/sbin/dhclient/clparse.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/clparse.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -296,12 +296,12 @@ parse_client_statement(FILE *cfile, struct interface_i
 	}
 }
 
-int
-parse_X(FILE *cfile, u_int8_t *buf, int max)
+unsigned
+parse_X(FILE *cfile, u_int8_t *buf, unsigned max)
 {
 	int	 token;
 	char	*val;
-	int	 len;
+	unsigned len;
 
 	token = peek_token(&val, cfile);
 	if (token == NUMBER_OR_NAME || token == NUMBER) {
@@ -685,14 +685,14 @@ parse_option_decl(FILE *cfile, struct option_data *opt
 	int		 token;
 	u_int8_t	 buf[4];
 	u_int8_t	 hunkbuf[1024];
-	int		 hunkix = 0;
+	unsigned	 hunkix = 0;
 	char		*vendor;
 	char		*fmt;
 	struct universe	*universe;
 	struct option	*option;
 	struct iaddr	 ip_addr;
 	u_int8_t	*dp;
-	int		 len;
+	unsigned	 len;
 	int		 nul_term = 0;
 
 	token = next_token(&val, cfile);

Modified: head/sbin/dhclient/conflex.c
==============================================================================
--- head/sbin/dhclient/conflex.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/conflex.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -60,8 +60,8 @@ int eol_token;
 
 static char line1[81];
 static char line2[81];
-static int lpos;
-static int line;
+static unsigned lpos;
+static unsigned line;
 static int tlpos;
 static int tline;
 static int token;
@@ -228,7 +228,8 @@ skip_to_eol(FILE *cfile)
 static int
 read_string(FILE *cfile)
 {
-	int	i, c, bs = 0;
+	int	c, bs = 0;
+	unsigned i;
 
 	for (i = 0; i < sizeof(tokbuf); i++) {
 		c = get_char(cfile);
@@ -263,7 +264,8 @@ read_string(FILE *cfile)
 static int
 read_number(int c, FILE *cfile)
 {
-	int	seenx = 0, i = 0, token = NUMBER;
+	int	seenx = 0, token = NUMBER;
+	unsigned i = 0;
 
 	tokbuf[i++] = c;
 	for (; i < sizeof(tokbuf); i++) {
@@ -290,7 +292,7 @@ read_number(int c, FILE *cfile)
 static int
 read_num_or_name(int c, FILE *cfile)
 {
-	int	i = 0;
+	unsigned i = 0;
 	int	rv = NUMBER_OR_NAME;
 
 	tokbuf[i++] = c;

Modified: head/sbin/dhclient/dhclient.c
==============================================================================
--- head/sbin/dhclient/dhclient.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/dhclient.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -195,7 +195,7 @@ get_ifa(char *cp, int n)
 	return (NULL);
 }
 
-struct iaddr defaddr = { 4 };
+struct iaddr defaddr = { .len = 4 };
 uint8_t curbssid[6];
 
 static void
@@ -237,7 +237,8 @@ routehandler(struct protocol *p)
 
 	n = read(routefd, &msg, sizeof(msg));
 	rtm = (struct rt_msghdr *)msg;
-	if (n < sizeof(rtm->rtm_msglen) || n < rtm->rtm_msglen ||
+	if (n < (ssize_t)sizeof(rtm->rtm_msglen) ||
+	    n < (ssize_t)rtm->rtm_msglen ||
 	    rtm->rtm_version != RTM_VERSION)
 		return;
 
@@ -2059,7 +2060,8 @@ priv_script_write_params(char *prefix, struct client_l
 {
 	struct interface_info *ip = ifi;
 	u_int8_t dbuf[1500], *dp = NULL;
-	int i, len;
+	int i;
+	size_t len;
 	char tbuf[128];
 
 	script_set_env(ip->client, prefix, "ip_address",
@@ -2209,12 +2211,14 @@ script_write_params(char *prefix, struct client_lease 
 		pr_len = strlen(prefix);
 
 	hdr.code = IMSG_SCRIPT_WRITE_PARAMS;
-	hdr.len = sizeof(hdr) + sizeof(struct client_lease) +
-	    sizeof(size_t) + fn_len + sizeof(size_t) + sn_len +
-	    sizeof(size_t) + pr_len;
+	hdr.len = sizeof(hdr) + sizeof(*lease) +
+	    sizeof(fn_len) + fn_len + sizeof(sn_len) + sn_len +
+	    sizeof(pr_len) + pr_len;
 
-	for (i = 0; i < 256; i++)
-		hdr.len += sizeof(int) + lease->options[i].len;
+	for (i = 0; i < 256; i++) {
+		hdr.len += sizeof(lease->options[i].len);
+		hdr.len += lease->options[i].len;
+	}
 
 	scripttime = time(NULL);
 
@@ -2223,7 +2227,7 @@ script_write_params(char *prefix, struct client_lease 
 
 	errs = 0;
 	errs += buf_add(buf, &hdr, sizeof(hdr));
-	errs += buf_add(buf, lease, sizeof(struct client_lease));
+	errs += buf_add(buf, lease, sizeof(*lease));
 	errs += buf_add(buf, &fn_len, sizeof(fn_len));
 	errs += buf_add(buf, lease->filename, fn_len);
 	errs += buf_add(buf, &sn_len, sizeof(sn_len));
@@ -2328,7 +2332,8 @@ void
 script_set_env(struct client_state *client, const char *prefix,
     const char *name, const char *value)
 {
-	int i, j, namelen;
+	int i, namelen;
+	size_t j;
 
 	/* No `` or $() command substitution allowed in environment values! */
 	for (j=0; j < strlen(value); j++)
@@ -2396,7 +2401,7 @@ script_flush_env(struct client_state *client)
 int
 dhcp_option_ev_name(char *buf, size_t buflen, struct option *option)
 {
-	int i;
+	size_t i;
 
 	for (i = 0; option->name[i]; i++) {
 		if (i + 1 == buflen)

Modified: head/sbin/dhclient/dhcpd.h
==============================================================================
--- head/sbin/dhclient/dhcpd.h	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/dhcpd.h	Thu Dec 14 15:41:32 2017	(r326853)
@@ -85,7 +85,7 @@
 #define	REMOTE_PORT	67
 
 struct option_data {
-	int		 len;
+	size_t		 len;
 	u_int8_t	*data;
 };
 
@@ -95,7 +95,7 @@ struct string_list {
 };
 
 struct iaddr {
-	int len;
+	size_t len;
 	unsigned char iabuf[16];
 };
 
@@ -288,9 +288,9 @@ char *parse_string(FILE *);
 int parse_ip_addr(FILE *, struct iaddr *);
 void parse_hardware_param(FILE *, struct hardware *);
 void parse_lease_time(FILE *, time_t *);
-unsigned char *parse_numeric_aggregate(FILE *, unsigned char *, int *,
-    int, int, int);
-void convert_num(unsigned char *, char *, int, int);
+unsigned char *parse_numeric_aggregate(FILE *, unsigned char *, size_t *,
+    int, unsigned, int);
+void convert_num(unsigned char *, char *, unsigned, int);
 time_t parse_date(FILE *);
 
 /* tree.c */
@@ -427,7 +427,7 @@ int read_client_conf(void);
 void read_client_leases(void);
 void parse_client_statement(FILE *, struct interface_info *,
     struct client_config *);
-int parse_X(FILE *, u_int8_t *, int);
+unsigned parse_X(FILE *, u_int8_t *, unsigned);
 int parse_option_list(FILE *, u_int8_t *);
 void parse_interface_declaration(FILE *, struct client_config *);
 struct interface_info *interface_or_dummy(char *);

Modified: head/sbin/dhclient/inet.c
==============================================================================
--- head/sbin/dhclient/inet.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/inet.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -56,7 +56,7 @@ struct iaddr
 subnet_number(struct iaddr addr, struct iaddr mask)
 {
 	struct iaddr rv;
-	int i;
+	unsigned i;
 
 	rv.len = 0;
 
@@ -79,7 +79,7 @@ struct iaddr
 broadcast_addr(struct iaddr subnet, struct iaddr mask)
 {
 	struct iaddr rv;
-	int i;
+	unsigned i;
 
 	if (subnet.len != mask.len) {
 		rv.len = 0;

Modified: head/sbin/dhclient/options.c
==============================================================================
--- head/sbin/dhclient/options.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/options.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -55,11 +55,11 @@ int bad_options_max = 5;
 
 void	parse_options(struct packet *);
 void	parse_option_buffer(struct packet *, unsigned char *, int);
-int	store_options(unsigned char *, int, struct tree_cache **,
+unsigned store_options(unsigned char *, int, struct tree_cache **,
 	    unsigned char *, int, int, int, int);
 void	expand_domain_search(struct packet *packet);
-int	find_search_domain_name_len(struct option_data *option, int *offset);
-void	expand_search_domain_name(struct option_data *option, int *offset,
+int	find_search_domain_name_len(struct option_data *option, size_t *offset);
+void	expand_search_domain_name(struct option_data *option, size_t *offset,
 	    unsigned char **domain_search);
 
 
@@ -213,7 +213,8 @@ parse_option_buffer(struct packet *packet,
 void
 expand_domain_search(struct packet *packet)
 {
-	int offset, expanded_len, next_domain_len;
+	size_t offset;
+	int expanded_len, next_domain_len;
 	struct option_data *option;
 	unsigned char *domain_search, *cursor;
 
@@ -257,9 +258,10 @@ expand_domain_search(struct packet *packet)
 }
 
 int
-find_search_domain_name_len(struct option_data *option, int *offset)
+find_search_domain_name_len(struct option_data *option, size_t *offset)
 {
-	int domain_name_len, i, label_len, pointer, pointed_len;
+	int domain_name_len, label_len, pointed_len;
+	size_t i, pointer;
 
 	domain_name_len = 0;
 
@@ -324,10 +326,11 @@ find_search_domain_name_len(struct option_data *option
 }
 
 void
-expand_search_domain_name(struct option_data *option, int *offset,
+expand_search_domain_name(struct option_data *option, size_t *offset,
     unsigned char **domain_search)
 {
-	int i, label_len, pointer;
+	int label_len;
+	size_t i, pointer;
 	unsigned char *cursor;
 
 	/*
@@ -381,8 +384,10 @@ cons_options(struct packet *inpacket, struct dhcp_pack
     int terminate, int bootpp, u_int8_t *prl, int prl_len)
 {
 	unsigned char priority_list[300], buffer[4096];
-	int priority_len, main_buffer_size, mainbufix, bufix;
-	int option_size, length;
+	unsigned priority_len;
+	size_t main_buffer_size;
+	unsigned option_size, bufix, mainbufix;
+	int length;
 
 	/*
 	 * If the client has provided a maximum DHCP message size, use
@@ -424,7 +429,7 @@ cons_options(struct packet *inpacket, struct dhcp_pack
 	 */
 	if (inpacket &&
 	    inpacket->options[DHO_DHCP_PARAMETER_REQUEST_LIST].data) {
-		int prlen =
+		unsigned prlen =
 		    inpacket->options[DHO_DHCP_PARAMETER_REQUEST_LIST].len;
 		if (prlen + priority_len > sizeof(priority_list))
 			prlen = sizeof(priority_list) - priority_len;
@@ -518,7 +523,7 @@ cons_options(struct packet *inpacket, struct dhcp_pack
 /*
  * Store all the requested options into the requested buffer.
  */
-int
+unsigned
 store_options(unsigned char *buffer, int buflen, struct tree_cache **options,
     unsigned char *priority_list, int priority_len, int first_cutoff,
     int second_cutoff, int terminate)

Modified: head/sbin/dhclient/packet.c
==============================================================================
--- head/sbin/dhclient/packet.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/packet.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -60,7 +60,7 @@ u_int32_t	wrapsum(u_int32_t);
 u_int32_t
 checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum)
 {
-	int i;
+	unsigned i;
 
 	/* Checksum all the pairs of bytes first... */
 	for (i = 0; i < (nbytes & ~1U); i += 2) {

Modified: head/sbin/dhclient/parse.c
==============================================================================
--- head/sbin/dhclient/parse.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/parse.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -158,7 +158,8 @@ void
 parse_hardware_param(FILE *cfile, struct hardware *hardware)
 {
 	unsigned char *t;
-	int token, hlen;
+	int token;
+	size_t hlen;
 	char *val;
 
 	token = next_token(&val, cfile);
@@ -242,13 +243,13 @@ parse_lease_time(FILE *cfile, time_t *timep)
  * tokenized.
  */
 unsigned char *
-parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
-    int separator, int base, int size)
+parse_numeric_aggregate(FILE *cfile, unsigned char *buf, size_t *max,
+    int separator, unsigned base, int size)
 {
 	unsigned char *bufp = buf, *s = NULL;
-	int token, count = 0;
+	int token;
 	char *val, *t;
-	size_t valsize;
+	size_t valsize, count = 0;
 	pair c = NULL;
 	unsigned char *lbufp = NULL;
 
@@ -329,14 +330,15 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *bu
 }
 
 void
-convert_num(unsigned char *buf, char *str, int base, int size)
+convert_num(unsigned char *buf, char *str, unsigned base, int size)
 {
-	int negative = 0, tval, max;
+	bool negative = false;
+	unsigned tval, max;
 	u_int32_t val = 0;
 	char *ptr = str;
 
 	if (*ptr == '-') {
-		negative = 1;
+		negative = true;
 		ptr++;
 	}
 

Modified: head/sbin/dhclient/privsep.c
==============================================================================
--- head/sbin/dhclient/privsep.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/privsep.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -76,7 +76,8 @@ buf_close(int sock, struct buf *buf)
 ssize_t
 buf_read(int sock, void *buf, size_t nbytes)
 {
-	ssize_t	n, r = 0;
+	ssize_t	n;
+	size_t r = 0;
 	char *p = buf;
 
 	do {
@@ -84,7 +85,7 @@ buf_read(int sock, void *buf, size_t nbytes)
 		if (n == 0)
 			error("connection closed");
 		if (n != -1) {
-			r += n;
+			r += (size_t)n;
 			p += n;
 			nbytes -= n;
 		}
@@ -107,9 +108,9 @@ dispatch_imsg(struct interface_info *ifi, int fd)
 	char			*medium, *reason, *filename,
 				*servername, *prefix;
 	size_t			 medium_len, reason_len, filename_len,
-				 servername_len, prefix_len, totlen;
+				 servername_len, optlen, prefix_len, totlen;
 	struct client_lease	 lease;
-	int			 ret, i, optlen;
+	int			 ret, i;
 	struct buf		*buf;
 	u_int16_t		mtu;
 

Modified: head/sbin/dhclient/tree.c
==============================================================================
--- head/sbin/dhclient/tree.c	Thu Dec 14 15:40:03 2017	(r326852)
+++ head/sbin/dhclient/tree.c	Thu Dec 14 15:41:32 2017	(r326853)
@@ -47,8 +47,6 @@ __FBSDID("$FreeBSD$");
 
 #include "dhcpd.h"
 
-extern int h_errno;
-
 pair
 cons(caddr_t car, pair cdr)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201712141541.vBEFfXmb038550>