From 1bb3831e13a65afd87078c88e0285d23b1e0bcdf Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Fri, 27 Jan 2012 01:21:41 +0000 Subject: [PATCH] 3267. [bug] Memory allocation failures could be mis-reported as unexpected error. New ISC_R_UNSET result code. [RT #27336] --- CHANGES | 4 ++++ lib/isc/include/isc/result.h | 5 +++-- lib/isc/result.c | 3 ++- lib/isc/unix/socket.c | 37 +++++++++++++++++++++--------------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index b747aa8e1a..95959d8ceb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +3267. [bug] Memory allocation failures could be mis-reported as + unexpected error. New ISC_R_UNSET result code. + [RT #27336] + 3266. [bug] The maximum number of NSEC3 iterations for a DNSKEY RRset was not being properly computed. [RT #26543] diff --git a/lib/isc/include/isc/result.h b/lib/isc/include/isc/result.h index 2347d5f80c..8b0c797c1b 100644 --- a/lib/isc/include/isc/result.h +++ b/lib/isc/include/isc/result.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: result.h,v 1.73 2009/09/02 23:48:03 tbox Exp $ */ +/* $Id: result.h,v 1.74 2012/01/27 01:21:41 marka Exp $ */ #ifndef ISC_RESULT_H #define ISC_RESULT_H 1 @@ -87,9 +87,10 @@ #define ISC_R_MAXSIZE 58 /*%< max size */ #define ISC_R_BADADDRESSFORM 59 /*%< invalid address format */ #define ISC_R_BADBASE32 60 /*%< bad base32 encoding */ +#define ISC_R_UNSET 61 /*%< unset */ /*% Not a result code: the number of results. */ -#define ISC_R_NRESULTS 61 +#define ISC_R_NRESULTS 62 ISC_LANG_BEGINDECLS diff --git a/lib/isc/result.c b/lib/isc/result.c index 571358054e..28269bafaf 100644 --- a/lib/isc/result.c +++ b/lib/isc/result.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: result.c,v 1.71 2008/09/25 04:02:39 tbox Exp $ */ +/* $Id: result.c,v 1.72 2012/01/27 01:21:41 marka Exp $ */ /*! \file */ @@ -102,6 +102,7 @@ static const char *text[ISC_R_NRESULTS] = { "max size", /*%< 58 */ "invalid address format", /*%< 59 */ "bad base32 encoding", /*%< 60 */ + "unset", /*%< 61 */ }; #define ISC_RESULT_RESULTSET 2 diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index f20f3d31ff..42d2b73e79 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.349 2011/11/29 01:03:47 marka Exp $ */ +/* $Id: socket.c,v 1.350 2012/01/27 01:21:41 marka Exp $ */ /*! \file */ @@ -1595,7 +1595,7 @@ allocate_socketevent(isc__socket_t *sock, isc_eventtype_t eventtype, if (ev == NULL) return (NULL); - ev->result = ISC_R_UNEXPECTED; + ev->result = ISC_R_UNSET; ISC_LINK_INIT(ev, ev_link); ISC_LIST_INIT(ev->bufferlist); ev->region.base = NULL; @@ -2048,8 +2048,6 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type, if (sock == NULL) return (ISC_R_NOMEMORY); - result = ISC_R_UNEXPECTED; - sock->common.magic = 0; sock->common.impmagic = 0; sock->references = 0; @@ -2078,8 +2076,10 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type, sock->recvcmsgbuflen = cmsgbuflen; if (sock->recvcmsgbuflen != 0U) { sock->recvcmsgbuf = isc_mem_get(manager->mctx, cmsgbuflen); - if (sock->recvcmsgbuf == NULL) + if (sock->recvcmsgbuf == NULL) { + result = ISC_R_NOMEMORY; goto error; + } } cmsgbuflen = 0; @@ -2096,8 +2096,10 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type, sock->sendcmsgbuflen = cmsgbuflen; if (sock->sendcmsgbuflen != 0U) { sock->sendcmsgbuf = isc_mem_get(manager->mctx, cmsgbuflen); - if (sock->sendcmsgbuf == NULL) + if (sock->sendcmsgbuf == NULL) { + result = ISC_R_NOMEMORY; goto error; + } } memset(sock->name, 0, sizeof(sock->name)); @@ -2235,7 +2237,9 @@ clear_bsdcompat(void) { static isc_result_t opensocket(isc__socketmgr_t *manager, isc__socket_t *sock, - isc__socket_t *dup_socket) { + isc__socket_t *dup_socket) +{ + isc_result_t result; char strbuf[ISC_STRERRORSIZE]; const char *err = "socket"; int tries = 0; @@ -2350,9 +2354,10 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock, if (dup_socket != NULL) goto setup_done; - if (make_nonblock(sock->fd) != ISC_R_SUCCESS) { + result = make_nonblock(sock->fd); + if (result != ISC_R_SUCCESS) { (void)close(sock->fd); - return (ISC_R_UNEXPECTED); + return (result); } #ifdef SO_BSDCOMPAT @@ -3247,10 +3252,12 @@ internal_accept(isc_task_t *me, isc_event_t *ev) { UNLOCK(&sock->lock); - if (fd != -1 && (make_nonblock(fd) != ISC_R_SUCCESS)) { - (void)close(fd); - fd = -1; - result = ISC_R_UNEXPECTED; + if (fd != -1) { + result = make_nonblock(fd); + if (result != ISC_R_SUCCESS) { + (void)close(fd); + fd = -1; + } } /* @@ -4609,7 +4616,7 @@ isc__socket_recv2(isc_socket_t *sock0, isc_region_t *region, isc__socket_t *sock = (isc__socket_t *)sock0; event->ev_sender = sock; - event->result = ISC_R_UNEXPECTED; + event->result = ISC_R_UNSET; ISC_LIST_INIT(event->bufferlist); event->region = *region; event->n = 0; @@ -4823,7 +4830,7 @@ isc__socket_sendto2(isc_socket_t *sock0, isc_region_t *region, if ((flags & ISC_SOCKFLAG_NORETRY) != 0) REQUIRE(sock->type == isc_sockettype_udp); event->ev_sender = sock; - event->result = ISC_R_UNEXPECTED; + event->result = ISC_R_UNSET; ISC_LIST_INIT(event->bufferlist); event->region = *region; event->n = 0;