Page MenuHomeFreeBSD

D14460.id39574.diff
No OneTemporary

D14460.id39574.diff

Index: sbin/dhclient/Makefile
===================================================================
--- sbin/dhclient/Makefile
+++ sbin/dhclient/Makefile
@@ -50,7 +50,8 @@
CFLAGS+=-DWITH_CASPER
.endif
-WARNS?= 3
+WARNS?= 4
+NO_WCAST_ALIGN= yes
HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
Index: sbin/dhclient/clparse.c
===================================================================
--- sbin/dhclient/clparse.c
+++ sbin/dhclient/clparse.c
@@ -687,7 +687,7 @@
u_int8_t hunkbuf[1024];
unsigned hunkix = 0;
char *vendor;
- char *fmt;
+ const char *fmt;
struct universe *universe;
struct option *option;
struct iaddr ip_addr;
Index: sbin/dhclient/conflex.c
===================================================================
--- sbin/dhclient/conflex.c
+++ sbin/dhclient/conflex.c
@@ -55,7 +55,7 @@
char *token_line;
char *prev_line;
char *cur_line;
-char *tlname;
+const char *tlname;
int eol_token;
static char line1[81];
@@ -78,7 +78,7 @@
static int intern(char *, int);
void
-new_parse(char *name)
+new_parse(const char *name)
{
tlname = name;
lpos = line = 1;
@@ -264,7 +264,7 @@
static int
read_number(int c, FILE *cfile)
{
- int seenx = 0, token = NUMBER;
+ int seenx = 0, _token = NUMBER;
unsigned i = 0;
tokbuf[i++] = c;
@@ -286,7 +286,7 @@
tokbuf[i] = 0;
tval = tokbuf;
- return (token);
+ return (_token);
}
static int
Index: sbin/dhclient/dhclient.c
===================================================================
--- sbin/dhclient/dhclient.c
+++ sbin/dhclient/dhclient.c
@@ -91,7 +91,7 @@
time_t cur_time;
time_t default_lease_time = 43200; /* 12 hours... */
-char *path_dhclient_conf = _PATH_DHCLIENT_CONF;
+const char *path_dhclient_conf = _PATH_DHCLIENT_CONF;
char *path_dhclient_db = NULL;
int log_perror = 1;
@@ -131,10 +131,10 @@
void usage(void);
int check_option(struct client_lease *l, int option);
int check_classless_option(unsigned char *data, int len);
-int ipv4addrs(char * buf);
+int ipv4addrs(const char * buf);
int res_hnok(const char *dn);
int check_search(const char *srch);
-char *option_as_string(unsigned int code, unsigned char *data, int len);
+const char *option_as_string(unsigned int code, unsigned char *data, int len);
int fork_privchld(int, int);
#define ROUNDUP(a) \
@@ -201,26 +201,25 @@
static void
disassoc(void *arg)
{
- struct interface_info *ifi = arg;
+ struct interface_info *_ifi = arg;
/*
* Clear existing state.
*/
- if (ifi->client->active != NULL) {
+ if (_ifi->client->active != NULL) {
script_init("EXPIRE", NULL);
script_write_params("old_",
- ifi->client->active);
- if (ifi->client->alias)
+ _ifi->client->active);
+ if (_ifi->client->alias)
script_write_params("alias_",
- ifi->client->alias);
+ _ifi->client->alias);
script_go();
}
- ifi->client->state = S_INIT;
+ _ifi->client->state = S_INIT;
}
-/* ARGSUSED */
void
-routehandler(struct protocol *p)
+routehandler(struct protocol *p __unused)
{
char msg[2048], *addr;
struct rt_msghdr *rtm;
@@ -230,7 +229,7 @@
struct ieee80211_join_event *jev;
struct client_lease *l;
time_t t = time(NULL);
- struct sockaddr *sa;
+ struct sockaddr_in *sa;
struct iaddr a;
ssize_t n;
int linkstat;
@@ -254,13 +253,13 @@
if (scripttime == 0 || t < scripttime + 10)
break;
- sa = get_ifa((char *)(ifam + 1), ifam->ifam_addrs);
+ sa = (struct sockaddr_in*)get_ifa((char *)(ifam + 1), ifam->ifam_addrs);
if (sa == NULL)
break;
if ((a.len = sizeof(struct in_addr)) > sizeof(a.iabuf))
error("king bula sez: len mismatch");
- memcpy(a.iabuf, &((struct sockaddr_in *)sa)->sin_addr, a.len);
+ memcpy(a.iabuf, &sa->sin_addr, a.len);
if (addr_eq(a, defaddr))
break;
@@ -271,7 +270,7 @@
if (l == NULL) /* added/deleted addr is not the one we set */
break;
- addr = inet_ntoa(((struct sockaddr_in *)sa)->sin_addr);
+ addr = inet_ntoa(sa->sin_addr);
if (rtm->rtm_type == RTM_NEWADDR) {
/*
* XXX: If someone other than us adds our address,
@@ -946,7 +945,7 @@
{
struct iaddrlist *ap;
void (*handler)(struct packet *);
- char *type;
+ const char *type;
switch (packet->packet_type) {
case DHCPOFFER:
@@ -984,7 +983,7 @@
struct client_lease *lease, *lp;
int i;
int arp_timeout_needed, stop_selecting;
- char *name = packet->options[DHO_DHCP_MESSAGE_TYPE].len ?
+ const char *name = packet->options[DHO_DHCP_MESSAGE_TYPE].len ?
"DHCPOFFER" : "BOOTREPLY";
/* If we're not receptive to an offer right now, or if the offer
@@ -1993,7 +1992,7 @@
}
void
-script_init(char *reason, struct string_list *medium)
+script_init(const char *reason, struct string_list *medium)
{
size_t len, mediumlen = 0;
struct imsg_hdr hdr;
@@ -2028,7 +2027,7 @@
}
void
-priv_script_init(char *reason, char *medium)
+priv_script_init(const char *reason, char *medium)
{
struct interface_info *ip = ifi;
@@ -2056,7 +2055,7 @@
}
void
-priv_script_write_params(char *prefix, struct client_lease *lease)
+priv_script_write_params(const char *prefix, struct client_lease *lease)
{
struct interface_info *ip = ifi;
u_int8_t dbuf[1500], *dp = NULL;
@@ -2196,7 +2195,7 @@
}
void
-script_write_params(char *prefix, struct client_lease *lease)
+script_write_params(const char *prefix, struct client_lease *lease)
{
size_t fn_len = 0, sn_len = 0, pr_len = 0;
struct imsg_hdr hdr;
@@ -2460,8 +2459,8 @@
int
check_option(struct client_lease *l, int option)
{
- char *opbuf;
- char *sbuf;
+ const char *opbuf;
+ const char *sbuf;
/* we use this, since this is what gets passed to dhclient-script */
@@ -2721,7 +2720,7 @@
* otherwise, return 0
*/
int
-ipv4addrs(char * buf)
+ipv4addrs(const char * buf)
{
struct in_addr jnk;
int count = 0;
@@ -2739,7 +2738,7 @@
}
-char *
+const char *
option_as_string(unsigned int code, unsigned char *data, int len)
{
static char optbuf[32768]; /* XXX */
Index: sbin/dhclient/dhcpd.h
===================================================================
--- sbin/dhclient/dhcpd.h
+++ sbin/dhclient/dhcpd.h
@@ -235,7 +235,7 @@
struct hash_bucket {
struct hash_bucket *next;
- unsigned char *name;
+ const unsigned char *name;
int len;
unsigned char *value;
};
@@ -258,26 +258,27 @@
/* options.c */
int cons_options(struct packet *, struct dhcp_packet *, int,
struct tree_cache **, int, int, int, u_int8_t *, int);
-char *pretty_print_option(unsigned int,
+const char *pretty_print_option(unsigned int,
unsigned char *, int, int, int);
void do_packet(struct interface_info *, struct dhcp_packet *,
int, unsigned int, struct iaddr, struct hardware *);
/* errwarn.c */
extern int warnings_occurred;
-void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
-int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
-int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
-int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
-int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
+void error(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
+int warning(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
+int note(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
+int debug(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
+int parse_warn(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
/* conflex.c */
extern int lexline, lexchar;
-extern char *token_line, *tlname;
+extern char *token_line;
+extern const char *tlname;
extern char comments[4096];
extern int comment_index;
extern int eol_token;
-void new_parse(char *);
+void new_parse(const char *);
int next_token(char **, FILE *);
int peek_token(char **, FILE *);
@@ -321,7 +322,7 @@
void got_one(struct protocol *);
void add_timeout(time_t, void (*)(void *), void *);
void cancel_timeout(void (*)(void *), void *);
-void add_protocol(char *, int, void (*)(struct protocol *), void *);
+void add_protocol(const char *, int, void (*)(struct protocol *), void *);
void remove_protocol(struct protocol *);
int interface_link_status(char *);
void interface_set_mtu_unpriv(int, u_int16_t);
@@ -329,8 +330,8 @@
/* hash.c */
struct hash_table *new_hash(void);
-void add_hash(struct hash_table *, unsigned char *, int, unsigned char *);
-unsigned char *hash_lookup(struct hash_table *, unsigned char *, int);
+void add_hash(struct hash_table *, const unsigned char *, int, unsigned char *);
+void *hash_lookup(struct hash_table *, unsigned char *, int);
/* tables.c */
extern struct option dhcp_options[256];
@@ -358,7 +359,7 @@
/* dhclient.c */
extern cap_channel_t *capsyslog;
-extern char *path_dhclient_conf;
+extern const char *path_dhclient_conf;
extern char *path_dhclient_db;
extern time_t cur_time;
extern int log_priority;
@@ -393,12 +394,12 @@
void rewrite_client_leases(void);
void write_client_lease(struct interface_info *, struct client_lease *, int);
-void priv_script_init(char *, char *);
-void priv_script_write_params(char *, struct client_lease *);
+void priv_script_init(const char *, char *);
+void priv_script_write_params(const char *, struct client_lease *);
int priv_script_go(void);
-void script_init(char *, struct string_list *);
-void script_write_params(char *, struct client_lease *);
+void script_init(const char *, struct string_list *);
+void script_write_params(const char *, struct client_lease *);
int script_go(void);
void client_envadd(struct client_state *,
const char *, const char *, const char *, ...);
@@ -442,7 +443,7 @@
/* privsep.c */
struct buf *buf_open(size_t);
-int buf_add(struct buf *, void *, size_t);
+int buf_add(struct buf *, const void *, size_t);
int buf_close(int, struct buf *);
ssize_t buf_read(int, void *, size_t);
void dispatch_imsg(struct interface_info *, int);
Index: sbin/dhclient/dispatch.c
===================================================================
--- sbin/dhclient/dispatch.c
+++ sbin/dhclient/dispatch.c
@@ -49,10 +49,14 @@
#include <sys/ioctl.h>
+#include <assert.h>
#include <net/if_media.h>
#include <ifaddrs.h>
#include <poll.h>
+/* Assert that pointer p is aligned to at least align bytes */
+#define assert_aligned(p, align) assert((((uintptr_t)p) & ((align) - 1)) == 0)
+
struct protocol *protocols;
struct timeout *timeouts;
static struct timeout *free_timeouts;
@@ -73,7 +77,6 @@
discover_interfaces(struct interface_info *iface)
{
struct ifaddrs *ifap, *ifa;
- struct sockaddr_in foo;
struct ifreq *tif;
if (getifaddrs(&ifap) != 0)
@@ -93,15 +96,30 @@
* and record it in a linked list.
*/
if (ifa->ifa_addr->sa_family == AF_LINK) {
- struct sockaddr_dl *foo =
- (struct sockaddr_dl *)ifa->ifa_addr;
+ struct sockaddr_dl *foo;
+ /*
+ * The implementation of getifaddrs should guarantee
+ * this alignment
+ */
+ assert_aligned(ifa->ifa_addr,
+ _Alignof(struct sockaddr_dl*));
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcast-align"
+#endif
+ foo = (struct sockaddr_dl *)ifa->ifa_addr;
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
iface->index = foo->sdl_index;
iface->hw_address.hlen = foo->sdl_alen;
iface->hw_address.htype = HTYPE_ETHER; /* XXX */
memcpy(iface->hw_address.haddr,
LLADDR(foo), foo->sdl_alen);
} else if (ifa->ifa_addr->sa_family == AF_INET) {
+ struct sockaddr_in foo;
struct iaddr addr;
memcpy(&foo, ifa->ifa_addr, sizeof(foo));
@@ -437,7 +455,7 @@
/* Add a protocol to the list of protocols... */
void
-add_protocol(char *name, int fd, void (*handler)(struct protocol *),
+add_protocol(const char *name, int fd, void (*handler)(struct protocol *),
void *local)
{
struct protocol *p;
Index: sbin/dhclient/errwarn.c
===================================================================
--- sbin/dhclient/errwarn.c
+++ sbin/dhclient/errwarn.c
@@ -49,7 +49,7 @@
#include "dhcpd.h"
-static void do_percentm(char *obuf, size_t size, char *ibuf);
+static void do_percentm(char *obuf, size_t size, const char *ibuf);
static char mbuf[1024];
static char fbuf[1024];
@@ -60,7 +60,7 @@
* Log an error message, then exit.
*/
void
-error(char *fmt, ...)
+error(const char *fmt, ...)
{
va_list list;
@@ -94,7 +94,7 @@
* Log a warning message...
*/
int
-warning(char *fmt, ...)
+warning(const char *fmt, ...)
{
va_list list;
@@ -120,7 +120,7 @@
* Log a note...
*/
int
-note(char *fmt, ...)
+note(const char *fmt, ...)
{
va_list list;
@@ -146,7 +146,7 @@
* Log a debug message...
*/
int
-debug(char *fmt, ...)
+debug(const char *fmt, ...)
{
va_list list;
@@ -172,10 +172,10 @@
* Find %m in the input string and substitute an error message string.
*/
static void
-do_percentm(char *obuf, size_t size, char *ibuf)
+do_percentm(char *obuf, size_t size, const char *ibuf)
{
char ch;
- char *s = ibuf;
+ const char *s = ibuf;
char *t = obuf;
size_t prlen;
size_t fmt_left;
@@ -205,7 +205,7 @@
}
int
-parse_warn(char *fmt, ...)
+parse_warn(const char *fmt, ...)
{
va_list list;
static char spaces[] =
Index: sbin/dhclient/hash.c
===================================================================
--- sbin/dhclient/hash.c
+++ sbin/dhclient/hash.c
@@ -47,7 +47,7 @@
#include "dhcpd.h"
-static int do_hash(unsigned char *, int, int);
+static int do_hash(const unsigned char *, int, int);
struct hash_table *
new_hash(void)
@@ -62,9 +62,9 @@
}
static int
-do_hash(unsigned char *name, int len, int size)
+do_hash(const unsigned char *name, int len, int size)
{
- unsigned char *s = name;
+ const unsigned char *s = name;
int accum = 0, i = len;
while (i--) {
@@ -77,7 +77,7 @@
return (accum % size);
}
-void add_hash(struct hash_table *table, unsigned char *name, int len,
+void add_hash(struct hash_table *table, const unsigned char *name, int len,
unsigned char *pointer)
{
struct hash_bucket *bp;
@@ -86,7 +86,7 @@
if (!table)
return;
if (!len)
- len = strlen((char *)name);
+ len = strlen((const char *)name);
hashno = do_hash(name, len, table->hash_count);
bp = new_hash_bucket();
@@ -102,7 +102,7 @@
table->buckets[hashno] = bp;
}
-unsigned char *
+void *
hash_lookup(struct hash_table *table, unsigned char *name, int len)
{
struct hash_bucket *bp;
Index: sbin/dhclient/options.c
===================================================================
--- sbin/dhclient/options.c
+++ sbin/dhclient/options.c
@@ -628,7 +628,7 @@
/*
* Format the specified option so that a human can easily read it.
*/
-char *
+const char *
pretty_print_option(unsigned int code, unsigned char *data, int len,
int emit_commas, int emit_quotes)
{
Index: sbin/dhclient/privsep.h
===================================================================
--- sbin/dhclient/privsep.h
+++ sbin/dhclient/privsep.h
@@ -46,6 +46,6 @@
};
struct buf *buf_open(size_t);
-int buf_add(struct buf *, void *, size_t);
+int buf_add(struct buf *, const void *, size_t);
int buf_close(int, struct buf *);
ssize_t buf_read(int sock, void *, size_t);
Index: sbin/dhclient/privsep.c
===================================================================
--- sbin/dhclient/privsep.c
+++ sbin/dhclient/privsep.c
@@ -39,7 +39,7 @@
}
int
-buf_add(struct buf *buf, void *data, size_t len)
+buf_add(struct buf *buf, const void *data, size_t len)
{
if (buf->wpos + len > buf->size)
return (-1);
Index: sbin/dhclient/tables.c
===================================================================
--- sbin/dhclient/tables.c
+++ sbin/dhclient/tables.c
@@ -440,11 +440,11 @@
for (i = 0; i < 256; i++) {
dhcp_universe.options[i] = &dhcp_options[i];
add_hash(dhcp_universe.hash,
- (unsigned char *)dhcp_options[i].name, 0,
+ (const unsigned char *)dhcp_options[i].name, 0,
(unsigned char *)&dhcp_options[i]);
}
universe_hash.hash_count = DEFAULT_HASH_SIZE;
add_hash(&universe_hash,
- (unsigned char *)dhcp_universe.name, 0,
+ (const unsigned char *)dhcp_universe.name, 0,
(unsigned char *)&dhcp_universe);
}
Index: sbin/dhclient/tests/fake.c
===================================================================
--- sbin/dhclient/tests/fake.c
+++ sbin/dhclient/tests/fake.c
@@ -9,7 +9,7 @@
extern jmp_buf env;
void
-error(char *fmt, ...)
+error(const char *fmt, ...)
{
va_list ap;
@@ -22,7 +22,7 @@
}
int
-warning(char *fmt, ...)
+warning(const char *fmt, ...)
{
va_list ap;
@@ -39,7 +39,7 @@
}
int
-note(char *fmt, ...)
+note(const char *fmt, ...)
{
int ret;
va_list ap;
Index: sbin/dhclient/tree.h
===================================================================
--- sbin/dhclient/tree.h
+++ sbin/dhclient/tree.h
@@ -57,14 +57,14 @@
};
struct universe {
- char *name;
+ const char *name;
struct hash_table *hash;
struct option *options[256];
};
struct option {
- char *name;
- char *format;
+ const char *name;
+ const char *format;
struct universe *universe;
unsigned char code;
};

File Metadata

Mime Type
text/plain
Expires
Sun, Aug 23, 11:25 AM (9 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37135640
Default Alt Text
D14460.id39574.diff (16 KB)

Event Timeline