From c41eca87fe6f4ecaa86814f6b5a80f8c2461d47a Mon Sep 17 00:00:00 2001 From: Shawn Routhier Date: Thu, 9 Sep 2010 22:24:01 +0000 Subject: [PATCH] Another batch of fixes: Correct error handling in DLPI [ISC-Bugs #20378] Remove __sun__ and __hpux__ typedefs in osdep.h as they are now being checked in configure. [ISC-Bugs #20443] Modify how the cmsg header is allocated the v6 send and received routines to compile on more compilers. [ISC-Bugs #20524] When parsing a domain name free the memory for the name after we are done with it. [ISC-Bugs #20824] --- RELNOTES | 11 +++++++++ common/dlpi.c | 19 +++++++-------- common/parse.c | 8 ++++++- common/socket.c | 60 +++++++++++++++++++++++++++++++++++++----------- includes/osdep.h | 10 +------- 5 files changed, 76 insertions(+), 32 deletions(-) diff --git a/RELNOTES b/RELNOTES index 34d527af8..7471d29d5 100644 --- a/RELNOTES +++ b/RELNOTES @@ -78,6 +78,17 @@ work on other platforms. Please report any problems and suggested fixes to [ISC-Bugs #21497] Add a little more randomness to rng seed in client thanks to a patch from Jeremiah Jinno. +- Correct error handling in DLPI [ISC-Bugs #20378] + +- Remove __sun__ and __hpux__ typedefs in osdep.h as they are now being + checked in configure. [ISC-Bugs #20443] + +- Modify how the cmsg header is allocated the v6 send and received routines + to compile on more compilers. [ISC-Bugs #20524] + +- When parsing a domain name free the memory for the name after we are + done with it. [ISC-Bugs #20824] + Changes since 4.2.0rc1 - Documentation cleanup covering multiple tickets diff --git a/common/dlpi.c b/common/dlpi.c index eb64342c7..002480ff6 100644 --- a/common/dlpi.c +++ b/common/dlpi.c @@ -3,7 +3,8 @@ Data Link Provider Interface (DLPI) network interface code. */ /* - * Copyright (c) 2004,2007,2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-2003 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any @@ -981,7 +982,7 @@ static int dlpibindack (fd, bufp) dlp = (union DL_primitives *)ctl.buf; - if (!expected (DL_BIND_ACK, dlp, flags) < 0) { + if (expected (DL_BIND_ACK, dlp, flags) == -1) { return -1; } @@ -1015,7 +1016,7 @@ static int dlpiokack (fd, bufp) dlp = (union DL_primitives *)ctl.buf; - if (!expected (DL_OK_ACK, dlp, flags) < 0) { + if (expected (DL_OK_ACK, dlp, flags) == -1) { return -1; } @@ -1049,7 +1050,7 @@ static int dlpiinfoack (fd, bufp) dlp = (union DL_primitives *) ctl.buf; - if (!expected (DL_INFO_ACK, dlp, flags) < 0) { + if (expected (DL_INFO_ACK, dlp, flags) == -1) { return -1; } @@ -1083,7 +1084,7 @@ int dlpiphysaddrack (fd, bufp) dlp = (union DL_primitives *)ctl.buf; - if (!expected (DL_PHYS_ADDR_ACK, dlp, flags) < 0) { + if (expected (DL_PHYS_ADDR_ACK, dlp, flags) == -1) { return -1; } @@ -1225,15 +1226,15 @@ static int expected (prim, dlp, msgflags) { if (msgflags != RS_HIPRI) { /* Message was not M_PCPROTO */ - return 0; + return -1; } - if (dlp -> dl_primitive != prim) { + if (dlp->dl_primitive != prim) { /* Incorrect/unexpected return message */ - return 0; + return -1; } - return 1; + return 0; } /* diff --git a/common/parse.c b/common/parse.c index 0d9626095..35224b3d7 100644 --- a/common/parse.c +++ b/common/parse.c @@ -3,7 +3,7 @@ Common parser code for dhcpd and dhclient. */ /* - * Copyright (c) 2004-2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-2003 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any @@ -5082,6 +5082,7 @@ int parse_option_token (rv, cfile, fmt, expr, uniform, lookups) unsigned len; struct iaddr addr; int compress; + isc_boolean_t freeval = ISC_FALSE; const char *f, *g; struct enumeration_value *e; @@ -5165,6 +5166,7 @@ int parse_option_token (rv, cfile, fmt, expr, uniform, lookups) return 0; } len = strlen (val); + freeval = ISC_TRUE; goto make_string; case 't': /* Text string... */ @@ -5181,6 +5183,10 @@ int parse_option_token (rv, cfile, fmt, expr, uniform, lookups) if (!make_const_data (&t, (const unsigned char *)val, len, 1, 1, MDL)) log_fatal ("No memory for concatenation"); + if (freeval == ISC_TRUE) { + dfree((char *)val, MDL); + freeval = ISC_FALSE; + } break; case 'N': diff --git a/common/socket.c b/common/socket.c index a05e01c90..3f4eac90a 100644 --- a/common/socket.c +++ b/common/socket.c @@ -3,7 +3,7 @@ BSD socket interface code... */ /* - * Copyright (c) 2004-2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-2003 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any @@ -566,6 +566,21 @@ static size_t CMSG_SPACE(size_t len) { #endif /* DHCPv6 */ #ifdef DHCPv6 +/* + * For both send_packet6() and receive_packet6() we need to allocate + * space for the cmsg header information. We do this once and reuse + * the buffer. + */ +static void *control_buf = NULL; +static size_t control_buf_len = 0; + +static void +allocate_cmsg_cbuf(void) { + control_buf_len = CMSG_SPACE(sizeof(struct in6_pktinfo)); + control_buf = dmalloc(control_buf_len, MDL); + return; +} + /* * For both send_packet6() and receive_packet6() we need to use the * sendmsg()/recvmsg() functions rather than the simpler send()/recv() @@ -593,10 +608,20 @@ ssize_t send_packet6(struct interface_info *interface, int result; struct in6_pktinfo *pktinfo; struct cmsghdr *cmsg; - union { - struct cmsghdr cmsg_sizer; - u_int8_t pktinfo_sizer[CMSG_SPACE(sizeof(struct in6_pktinfo))]; - } control_buf; + + /* + * If necessary allocate space for the control message header. + * The space is common between send and receive. + */ + + if (control_buf == NULL) { + allocate_cmsg_cbuf(); + if (control_buf == NULL) { + log_error("send_packet6: unable to allocate cmsg header"); + return(ENOMEM); + } + } + memset(control_buf, 0, control_buf_len); /* * Initialize our message header structure. @@ -627,8 +652,8 @@ ssize_t send_packet6(struct interface_info *interface, * source address if we wanted, but we can safely let the * kernel decide what that should be. */ - m.msg_control = &control_buf; - m.msg_controllen = sizeof(control_buf); + m.msg_control = control_buf; + m.msg_controllen = control_buf_len; cmsg = CMSG_FIRSTHDR(&m); cmsg->cmsg_level = IPPROTO_IPV6; cmsg->cmsg_type = IPV6_PKTINFO; @@ -694,10 +719,19 @@ receive_packet6(struct interface_info *interface, struct cmsghdr *cmsg; struct in6_pktinfo *pktinfo; int found_pktinfo; - union { - struct cmsghdr cmsg_sizer; - u_int8_t pktinfo_sizer[CMSG_SPACE(sizeof(struct in6_pktinfo))]; - } control_buf; + + /* + * If necessary allocate space for the control message header. + * The space is common between send and receive. + */ + if (control_buf == NULL) { + allocate_cmsg_cbuf(); + if (control_buf == NULL) { + log_error("send_packet6: unable to allocate cmsg header"); + return(ENOMEM); + } + } + memset(control_buf, 0, control_buf_len); /* * Initialize our message header structure. @@ -728,8 +762,8 @@ receive_packet6(struct interface_info *interface, * information (when we initialized the interface), so we * should get the destination address from that. */ - m.msg_control = &control_buf; - m.msg_controllen = sizeof(control_buf); + m.msg_control = control_buf; + m.msg_controllen = control_buf_len; result = recvmsg(interface->rfdesc, &m, 0); diff --git a/includes/osdep.h b/includes/osdep.h index 63e676e4e..a8d8bb787 100644 --- a/includes/osdep.h +++ b/includes/osdep.h @@ -3,7 +3,7 @@ Operating system dependencies... */ /* - * Copyright (c) 2004-2005,2007-2009 by Internet Systems Consortium, + * Copyright (c) 2004-2005,2007-2010 by Internet Systems Consortium, * Inc. ("ISC") * Copyright (c) 1996-2003 by Internet Software Consortium * @@ -41,14 +41,6 @@ #include "config.h" #include -/* XXX: now that we have a nice autoconf, we should sense this in - * ./configure. - */ -#if defined(__sun__) || defined(__hpux__) -typedef uint8_t u_int8_t; -typedef uint16_t u_int16_t; -typedef uint32_t u_int32_t; -#endif #ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN 1234 -- 2.47.3