From 1be0b42978b4e5f06cc9246874b99982693b78b4 Mon Sep 17 00:00:00 2001 From: krw Date: Sun, 9 Apr 2017 20:44:13 +0000 Subject: [PATCH] Seven casts, a couple of tweaks and CFLAGS+=-Wsign-compare for the win. No intentional functional change. --- sbin/dhclient/Makefile | 3 ++- sbin/dhclient/conflex.c | 4 ++-- sbin/dhclient/dhclient.c | 12 +++++++----- sbin/dhclient/kroute.c | 12 +++--------- sbin/dhclient/options.c | 8 ++++---- sbin/dhclient/parse.c | 6 +++--- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/sbin/dhclient/Makefile b/sbin/dhclient/Makefile index 1ff3bf15067..685425f0473 100644 --- a/sbin/dhclient/Makefile +++ b/sbin/dhclient/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.18 2017/04/06 22:41:39 krw Exp $ +# $OpenBSD: Makefile,v 1.19 2017/04/09 20:44:13 krw Exp $ # # Copyright (c) 1996, 1997 The Internet Software Consortium. # All rights reserved. @@ -45,5 +45,6 @@ CFLAGS+=-Wall CFLAGS+=-Wstrict-prototypes -Wmissing-prototypes CFLAGS+=-Wmissing-declarations CFLAGS+=-Wshadow -Wpointer-arith -Wcast-qual +CFLAGS+=-Wsign-compare .include diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c index e52f204b338..cc166367197 100644 --- a/sbin/dhclient/conflex.c +++ b/sbin/dhclient/conflex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conflex.c,v 1.37 2017/04/08 20:16:04 krw Exp $ */ +/* $OpenBSD: conflex.c,v 1.38 2017/04/09 20:44:13 krw Exp $ */ /* Lexical scanner for dhclient config file. */ @@ -128,7 +128,7 @@ get_char(FILE *cfile) lpos = 1; cur_line[0] = 0; } else if (c != EOF) { - if (lpos < sizeof(line1)) { + if ((unsigned int)lpos < sizeof(line1)) { cur_line[lpos - 1] = c; cur_line[lpos] = 0; } diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index fa9c077221d..6daa095855a 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.410 2017/04/08 20:16:04 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.411 2017/04/09 20:44:13 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -256,9 +256,11 @@ routehandler(struct interface_info *ifi) do { n = read(routefd, rtmmsg, 2048); } while (n == -1 && errno == EINTR); + if (n == -1) + goto done; rtm = (struct rt_msghdr *)rtmmsg; - if (n < sizeof(rtm->rtm_msglen) || n < rtm->rtm_msglen || + if ((size_t)n < sizeof(rtm->rtm_msglen) || n < rtm->rtm_msglen || rtm->rtm_version != RTM_VERSION) goto done; @@ -268,7 +270,7 @@ routehandler(struct interface_info *ifi) rtm->rtm_priority != RTP_PROPOSAL_DHCLIENT) goto done; if ((rtm->rtm_flags & RTF_PROTO3) != 0) { - if (rtm->rtm_seq == client->xid) { + if (rtm->rtm_seq == (int32_t)client->xid) { client->flags |= IN_CHARGE; goto done; } else if ((client->flags & IN_CHARGE) != 0) { @@ -620,7 +622,7 @@ main(int argc, char *argv[]) } else if (fstat(tailfd, &sb) == -1) { fatal("Cannot stat /etc/resolv.conf.tail"); } else { - if (sb.st_size > 0 && sb.st_size < SIZE_MAX) { + if (sb.st_size > 0 && sb.st_size < LLONG_MAX) { config->resolv_tail = calloc(1, sb.st_size + 1); if (config->resolv_tail == NULL) { fatalx("no memory for resolv.conf.tail " @@ -2591,7 +2593,7 @@ priv_write_file(char *path, int flags, mode_t mode, n = write(fd, contents, sz); if (n == -1) log_warn("Couldn't write contents to '%s'", path); - else if (n < sz) + else if ((size_t)n < sz) log_warnx("Short contents write to '%s' (%zd vs %zu)", path, n, sz); diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 3c90ee1c06b..5686aea5a99 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.87 2017/04/08 20:16:04 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.88 2017/04/09 20:44:13 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback @@ -638,14 +638,8 @@ create_route_label(struct sockaddr_rtlabel *label) len = snprintf(label->sr_label, sizeof(label->sr_label), "DHCLIENT %d", (int)getpid()); - if (len == -1) { - log_warn("creating route label"); - return (1); - } - - if (len >= sizeof(label->sr_label)) { - log_warnx("creating route label: label too long (%d vs %zu)", - len, sizeof(label->sr_label)); + if (len == -1 || (unsigned int)len >= sizeof(label->sr_label)) { + log_warn("could not create route label"); return (1); } diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 77cd61bda44..62c1bcaf6b7 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.87 2017/04/08 20:16:04 krw Exp $ */ +/* $OpenBSD: options.c,v 1.88 2017/04/09 20:44:13 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -270,7 +270,7 @@ pretty_print_classless_routes(unsigned char *src, size_t srclen) bytes > sizeof(net.s_addr)) return (NULL); rslt = snprintf(bitsbuf, sizeof(bitsbuf), "/%d ", bits); - if (rslt == -1 || rslt >= sizeof(bitsbuf)) + if (rslt == -1 || (unsigned int)rslt >= sizeof(bitsbuf)) return (NULL); memset(&net, 0, sizeof(net)); @@ -286,8 +286,8 @@ pretty_print_classless_routes(unsigned char *src, size_t srclen) strlcat(string, ", ", sizeof(string)); strlcat(string, inet_ntoa(net), sizeof(string)); strlcat(string, bitsbuf, sizeof(string)); - rslt = strlcat(string, inet_ntoa(gateway), sizeof(string)); - if (rslt >= sizeof(string)) + if (strlcat(string, inet_ntoa(gateway), sizeof(string)) >= + sizeof(string)) return (NULL); } diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c index 51328276d7f..082f15fd4ee 100644 --- a/sbin/dhclient/parse.c +++ b/sbin/dhclient/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.49 2017/04/08 20:16:04 krw Exp $ */ +/* $OpenBSD: parse.c,v 1.50 2017/04/09 20:44:13 krw Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -428,9 +428,9 @@ parse_warn(char *msg) log_warnx("%s line %d: %s", tlname, lexline, msg); log_warnx("%s", token_line); - if (lexchar < sizeof(spaces)) { + if ((unsigned int)lexchar < sizeof(spaces)) { memset(spaces, 0, sizeof(spaces)); - for (i = 0; i < lexchar - 1; i++) { + for (i = 0; (int)i < lexchar - 1; i++) { if (token_line[i] == '\t') spaces[i] = '\t'; else -- 2.20.1