diff options
Diffstat (limited to 'lib/isc')
36 files changed, 576 insertions, 317 deletions
diff --git a/lib/isc/api b/lib/isc/api index 38bb8eb7d7950..9a572b2d2e741 100644 --- a/lib/isc/api +++ b/lib/isc/api @@ -4,6 +4,6 @@ # 9.8: 80-89, 120-129 # 9.9: 90-109 # 9.9-sub: 130-139 -LIBINTERFACE = 104 -LIBREVISION = 2 +LIBINTERFACE = 106 +LIBREVISION = 0 LIBAGE = 0 diff --git a/lib/isc/assertions.c b/lib/isc/assertions.c index 31c4fe7c9f273..6b6f52db1ac35 100644 --- a/lib/isc/assertions.c +++ b/lib/isc/assertions.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007-2009 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007-2009, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1997-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -27,6 +27,7 @@ #include <isc/assertions.h> #include <isc/backtrace.h> #include <isc/msgs.h> +#include <isc/print.h> #include <isc/result.h> /* diff --git a/lib/isc/backtrace.c b/lib/isc/backtrace.c index 2a510421474f4..f7a293c0f3d4d 100644 --- a/lib/isc/backtrace.c +++ b/lib/isc/backtrace.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2013, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2009, 2013-2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -221,17 +221,17 @@ isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) { #endif isc_result_t -isc_backtrace_getsymbolfromindex(int index, const void **addrp, +isc_backtrace_getsymbolfromindex(int idx, const void **addrp, const char **symbolp) { REQUIRE(addrp != NULL && *addrp == NULL); REQUIRE(symbolp != NULL && *symbolp == NULL); - if (index < 0 || index >= isc__backtrace_nsymbols) + if (idx < 0 || idx >= isc__backtrace_nsymbols) return (ISC_R_RANGE); - *addrp = isc__backtrace_symtable[index].addr; - *symbolp = isc__backtrace_symtable[index].symbol; + *addrp = isc__backtrace_symtable[idx].addr; + *symbolp = isc__backtrace_symtable[idx].symbol; return (ISC_R_SUCCESS); } diff --git a/lib/isc/commandline.c b/lib/isc/commandline.c index 98546db48f388..416fba1927a62 100644 --- a/lib/isc/commandline.c +++ b/lib/isc/commandline.c @@ -1,5 +1,5 @@ /* - * Portions Copyright (C) 2004, 2005, 2007, 2008, 2014 Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 2004, 2005, 2007, 2008, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (C) 1999-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -65,6 +65,7 @@ #include <isc/commandline.h> #include <isc/msgs.h> +#include <isc/print.h> #include <isc/string.h> #include <isc/util.h> diff --git a/lib/isc/entropy.c b/lib/isc/entropy.c index da9e81fb3129a..66c196e5f7186 100644 --- a/lib/isc/entropy.c +++ b/lib/isc/entropy.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007, 2009, 2010 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2007, 2009, 2010, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2000-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -40,6 +40,7 @@ #include <isc/msgs.h> #include <isc/mutex.h> #include <isc/platform.h> +#include <isc/print.h> #include <isc/region.h> #include <isc/sha1.h> #include <isc/string.h> @@ -316,7 +317,12 @@ entropypool_adddata(isc_entropy_t *ent, void *p, unsigned int len, unsigned long addr; isc_uint8_t *buf; + /* Silly MSVC in 64 bit mode complains here... */ +#ifdef _WIN64 + addr = (unsigned long)((unsigned long long)p); +#else addr = (unsigned long)p; +#endif buf = p; if ((addr & 0x03U) != 0U) { diff --git a/lib/isc/error.c b/lib/isc/error.c index 095100a7c9436..b15881589eb41 100644 --- a/lib/isc/error.c +++ b/lib/isc/error.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -26,6 +26,7 @@ #include <isc/error.h> #include <isc/msgs.h> +#include <isc/print.h> /*% Default unexpected callback. */ static void diff --git a/lib/isc/heap.c b/lib/isc/heap.c index 9d4fd28adc3e1..3dd23cf56b562 100644 --- a/lib/isc/heap.c +++ b/lib/isc/heap.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007, 2010-2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2007, 2010-2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1997-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -74,7 +74,7 @@ struct isc_heap { isc_result_t isc_heap_create(isc_mem_t *mctx, isc_heapcompare_t compare, - isc_heapindex_t index, unsigned int size_increment, + isc_heapindex_t idx, unsigned int size_increment, isc_heap_t **heapp) { isc_heap_t *heap; @@ -96,7 +96,7 @@ isc_heap_create(isc_mem_t *mctx, isc_heapcompare_t compare, heap->last = 0; heap->array = NULL; heap->compare = compare; - heap->index = index; + heap->index = idx; *heapp = heap; @@ -203,14 +203,14 @@ isc_heap_insert(isc_heap_t *heap, void *elt) { } void -isc_heap_delete(isc_heap_t *heap, unsigned int index) { +isc_heap_delete(isc_heap_t *heap, unsigned int idx) { void *elt; isc_boolean_t less; REQUIRE(VALID_HEAP(heap)); - REQUIRE(index >= 1 && index <= heap->last); + REQUIRE(idx >= 1 && idx <= heap->last); - if (index == heap->last) { + if (idx == heap->last) { heap->array[heap->last] = NULL; heap->last--; } else { @@ -218,38 +218,38 @@ isc_heap_delete(isc_heap_t *heap, unsigned int index) { heap->array[heap->last] = NULL; heap->last--; - less = heap->compare(elt, heap->array[index]); - heap->array[index] = elt; + less = heap->compare(elt, heap->array[idx]); + heap->array[idx] = elt; if (less) - float_up(heap, index, heap->array[index]); + float_up(heap, idx, heap->array[idx]); else - sink_down(heap, index, heap->array[index]); + sink_down(heap, idx, heap->array[idx]); } } void -isc_heap_increased(isc_heap_t *heap, unsigned int index) { +isc_heap_increased(isc_heap_t *heap, unsigned int idx) { REQUIRE(VALID_HEAP(heap)); - REQUIRE(index >= 1 && index <= heap->last); + REQUIRE(idx >= 1 && idx <= heap->last); - float_up(heap, index, heap->array[index]); + float_up(heap, idx, heap->array[idx]); } void -isc_heap_decreased(isc_heap_t *heap, unsigned int index) { +isc_heap_decreased(isc_heap_t *heap, unsigned int idx) { REQUIRE(VALID_HEAP(heap)); - REQUIRE(index >= 1 && index <= heap->last); + REQUIRE(idx >= 1 && idx <= heap->last); - sink_down(heap, index, heap->array[index]); + sink_down(heap, idx, heap->array[idx]); } void * -isc_heap_element(isc_heap_t *heap, unsigned int index) { +isc_heap_element(isc_heap_t *heap, unsigned int idx) { REQUIRE(VALID_HEAP(heap)); - REQUIRE(index >= 1); + REQUIRE(idx >= 1); - if (index <= heap->last) - return (heap->array[index]); + if (idx <= heap->last) + return (heap->array[idx]); return (NULL); } diff --git a/lib/isc/hmacmd5.c b/lib/isc/hmacmd5.c index 9c10532c53c17..d27bfe42a786f 100644 --- a/lib/isc/hmacmd5.c +++ b/lib/isc/hmacmd5.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007, 2009, 2013, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2007, 2009, 2013-2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2000, 2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -159,5 +159,5 @@ isc_hmacmd5_verify2(isc_hmacmd5_t *ctx, unsigned char *digest, size_t len) { REQUIRE(len <= ISC_MD5_DIGESTLENGTH); isc_hmacmd5_sign(ctx, newdigest); - return (isc_safe_memcmp(digest, newdigest, len)); + return (isc_safe_memequal(digest, newdigest, len)); } diff --git a/lib/isc/hmacsha.c b/lib/isc/hmacsha.c index 1f72330d35cec..fa905e0685696 100644 --- a/lib/isc/hmacsha.c +++ b/lib/isc/hmacsha.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007, 2009, 2011-2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2005-2007, 2009, 2011-2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -604,7 +604,7 @@ isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) { REQUIRE(len <= ISC_SHA1_DIGESTLENGTH); isc_hmacsha1_sign(ctx, newdigest, ISC_SHA1_DIGESTLENGTH); - return (isc_safe_memcmp(digest, newdigest, len)); + return (isc_safe_memequal(digest, newdigest, len)); } /* @@ -617,7 +617,7 @@ isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len) REQUIRE(len <= ISC_SHA224_DIGESTLENGTH); isc_hmacsha224_sign(ctx, newdigest, ISC_SHA224_DIGESTLENGTH); - return (isc_safe_memcmp(digest, newdigest, len)); + return (isc_safe_memequal(digest, newdigest, len)); } /* @@ -630,7 +630,7 @@ isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len) REQUIRE(len <= ISC_SHA256_DIGESTLENGTH); isc_hmacsha256_sign(ctx, newdigest, ISC_SHA256_DIGESTLENGTH); - return (isc_safe_memcmp(digest, newdigest, len)); + return (isc_safe_memequal(digest, newdigest, len)); } /* @@ -643,7 +643,7 @@ isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len) REQUIRE(len <= ISC_SHA384_DIGESTLENGTH); isc_hmacsha384_sign(ctx, newdigest, ISC_SHA384_DIGESTLENGTH); - return (isc_safe_memcmp(digest, newdigest, len)); + return (isc_safe_memequal(digest, newdigest, len)); } /* @@ -656,5 +656,5 @@ isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len) REQUIRE(len <= ISC_SHA512_DIGESTLENGTH); isc_hmacsha512_sign(ctx, newdigest, ISC_SHA512_DIGESTLENGTH); - return (isc_safe_memcmp(digest, newdigest, len)); + return (isc_safe_memequal(digest, newdigest, len)); } diff --git a/lib/isc/httpd.c b/lib/isc/httpd.c index 0c159f069df81..241c1d53a8d51 100644 --- a/lib/isc/httpd.c +++ b/lib/isc/httpd.c @@ -23,6 +23,7 @@ #include <isc/buffer.h> #include <isc/httpd.h> #include <isc/mem.h> +#include <isc/print.h> #include <isc/socket.h> #include <isc/string.h> #include <isc/task.h> @@ -61,6 +62,7 @@ #define HTTPD_CLOSE 0x0001 /* Got a Connection: close header */ #define HTTPD_FOUNDHOST 0x0002 /* Got a Host: header */ +#define HTTPD_KEEPALIVE 0x0004 /* Got a Connection: Keep-Alive */ /*% http client */ struct isc_httpd { @@ -236,39 +238,40 @@ isc_result_t isc_httpdmgr_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task, isc_httpdclientok_t *client_ok, isc_httpdondestroy_t *ondestroy, void *cb_arg, - isc_timermgr_t *tmgr, isc_httpdmgr_t **httpdp) + isc_timermgr_t *tmgr, isc_httpdmgr_t **httpdmgrp) { isc_result_t result; - isc_httpdmgr_t *httpd; + isc_httpdmgr_t *httpdmgr; REQUIRE(mctx != NULL); REQUIRE(sock != NULL); REQUIRE(task != NULL); REQUIRE(tmgr != NULL); - REQUIRE(httpdp != NULL && *httpdp == NULL); + REQUIRE(httpdmgrp != NULL && *httpdmgrp == NULL); - httpd = isc_mem_get(mctx, sizeof(isc_httpdmgr_t)); - if (httpd == NULL) + httpdmgr = isc_mem_get(mctx, sizeof(isc_httpdmgr_t)); + if (httpdmgr == NULL) return (ISC_R_NOMEMORY); - result = isc_mutex_init(&httpd->lock); + result = isc_mutex_init(&httpdmgr->lock); if (result != ISC_R_SUCCESS) { - isc_mem_put(mctx, httpd, sizeof(isc_httpdmgr_t)); + isc_mem_put(mctx, httpdmgr, sizeof(isc_httpdmgr_t)); return (result); } - httpd->mctx = NULL; - isc_mem_attach(mctx, &httpd->mctx); - httpd->sock = NULL; - isc_socket_attach(sock, &httpd->sock); - httpd->task = NULL; - isc_task_attach(task, &httpd->task); - httpd->timermgr = tmgr; /* XXXMLG no attach function? */ - httpd->client_ok = client_ok; - httpd->ondestroy = ondestroy; - httpd->cb_arg = cb_arg; - - ISC_LIST_INIT(httpd->running); - ISC_LIST_INIT(httpd->urls); + httpdmgr->mctx = NULL; + isc_mem_attach(mctx, &httpdmgr->mctx); + httpdmgr->sock = NULL; + isc_socket_attach(sock, &httpdmgr->sock); + httpdmgr->task = NULL; + isc_task_attach(task, &httpdmgr->task); + httpdmgr->timermgr = tmgr; /* XXXMLG no attach function? */ + httpdmgr->client_ok = client_ok; + httpdmgr->ondestroy = ondestroy; + httpdmgr->cb_arg = cb_arg; + httpdmgr->flags = 0; + + ISC_LIST_INIT(httpdmgr->running); + ISC_LIST_INIT(httpdmgr->urls); /* XXXMLG ignore errors on isc_socket_listen() */ result = isc_socket_listen(sock, SOMAXCONN); @@ -281,22 +284,22 @@ isc_httpdmgr_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task, (void)isc_socket_filter(sock, "httpready"); - result = isc_socket_accept(sock, task, isc_httpd_accept, httpd); + result = isc_socket_accept(sock, task, isc_httpd_accept, httpdmgr); if (result != ISC_R_SUCCESS) goto cleanup; - httpd->render_404 = render_404; - httpd->render_500 = render_500; + httpdmgr->render_404 = render_404; + httpdmgr->render_500 = render_500; - *httpdp = httpd; + *httpdmgrp = httpdmgr; return (ISC_R_SUCCESS); cleanup: - isc_task_detach(&httpd->task); - isc_socket_detach(&httpd->sock); - isc_mem_detach(&httpd->mctx); - (void)isc_mutex_destroy(&httpd->lock); - isc_mem_put(mctx, httpd, sizeof(isc_httpdmgr_t)); + isc_task_detach(&httpdmgr->task); + isc_socket_detach(&httpdmgr->sock); + isc_mem_detach(&httpdmgr->mctx); + (void)isc_mutex_destroy(&httpdmgr->lock); + isc_mem_put(mctx, httpdmgr, sizeof(isc_httpdmgr_t)); return (result); } @@ -481,6 +484,13 @@ process_request(isc_httpd_t *httpd, int length) { if (strstr(s, "Host: ") != NULL) httpd->flags |= HTTPD_FOUNDHOST; + if (strncmp(httpd->protocol, "HTTP/1.0", 8) == 0) { + if (strcasestr(s, "Connection: Keep-Alive") != NULL) + httpd->flags |= HTTPD_KEEPALIVE; + else + httpd->flags |= HTTPD_CLOSE; + } + /* * Standards compliance hooks here. */ @@ -595,7 +605,7 @@ render_404(const char *url, isc_httpdurl_t *urlinfo, const char **mimetype, isc_buffer_t *b, isc_httpdfree_t **freecb, void **freecb_args) { - static char msg[] = "No such URL."; + static char msg[] = "No such URL.\r\n"; UNUSED(url); UNUSED(urlinfo); @@ -621,7 +631,7 @@ render_500(const char *url, isc_httpdurl_t *urlinfo, const char **mimetype, isc_buffer_t *b, isc_httpdfree_t **freecb, void **freecb_args) { - static char msg[] = "Internal server failure."; + static char msg[] = "Internal server failure.\r\n"; UNUSED(url); UNUSED(urlinfo); @@ -724,6 +734,8 @@ isc_httpd_recvdone(isc_task_t *task, isc_event_t *ev) { } isc_httpd_response(httpd); + if ((httpd->flags & HTTPD_KEEPALIVE) != 0) + isc_httpd_addheader(httpd, "Connection", "Keep-Alive"); isc_httpd_addheader(httpd, "Content-Type", httpd->mimetype); isc_httpd_addheader(httpd, "Date", datebuf); isc_httpd_addheader(httpd, "Expires", datebuf); diff --git a/lib/isc/include/isc/app.h b/lib/isc/include/isc/app.h index 53810859ce4e4..7a2f68b0dc984 100644 --- a/lib/isc/include/isc/app.h +++ b/lib/isc/include/isc/app.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007, 2009, 2013 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2007, 2009, 2013, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -203,6 +203,16 @@ isc_app_run(void); *\li ISC_R_RELOAD Reload has been requested. */ +isc_boolean_t +isc_app_isrunning(void); +/*!< + * \brief Return if the ISC library application is running. + * + * Returns: + *\li ISC_TRUE App is running. + *\li ISC_FALSE App is not running. + */ + isc_result_t isc_app_ctxshutdown(isc_appctx_t *ctx); diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 320d0d83138b3..45a4fa1312f91 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2012, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1997-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -15,8 +15,6 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id$ */ - #ifndef ISC_MEM_H #define ISC_MEM_H 1 @@ -50,7 +48,14 @@ typedef void (*isc_memfree_t)(void *, void *); /*% * Define ISC_MEM_CHECKOVERRUN=1 to turn on checks for using memory outside * the requested space. This will increase the size of each allocation. + * + * If we are performing a Coverity static analysis then ISC_MEM_CHECKOVERRUN + * can hide bugs that would otherwise discovered so force to zero. */ +#ifdef __COVERITY__ +#undef ISC_MEM_CHECKOVERRUN +#define ISC_MEM_CHECKOVERRUN 0 +#endif #ifndef ISC_MEM_CHECKOVERRUN #define ISC_MEM_CHECKOVERRUN 1 #endif @@ -60,7 +65,14 @@ typedef void (*isc_memfree_t)(void *, void *); * with the byte string '0xbe'. This helps track down uninitialized pointers * and the like. On freeing memory, the space is filled with '0xde' for * the same reasons. + * + * If we are performing a Coverity static analysis then ISC_MEM_FILL + * can hide bugs that would otherwise discovered so force to zero. */ +#ifdef __COVERITY__ +#undef ISC_MEM_FILL +#define ISC_MEM_FILL 0 +#endif #ifndef ISC_MEM_FILL #define ISC_MEM_FILL 1 #endif @@ -75,6 +87,8 @@ typedef void (*isc_memfree_t)(void *, void *); #endif LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging; +LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; + /*@{*/ #define ISC_MEM_DEBUGTRACE 0x00000001U #define ISC_MEM_DEBUGRECORD 0x00000002U diff --git a/lib/isc/include/isc/namespace.h b/lib/isc/include/isc/namespace.h index 4cfb305ca003b..5696bc8e9a301 100644 --- a/lib/isc/include/isc/namespace.h +++ b/lib/isc/include/isc/namespace.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2009-2013, 2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -29,6 +29,7 @@ #define isc_app_ctxstart isc__app_ctxstart #define isc_app_onrun isc__app_onrun #define isc_app_run isc__app_run +#define isc_app_isrunning isc__app_isrunning #define isc_app_ctxrun isc__app_ctxrun #define isc_app_shutdown isc__app_shutdown #define isc_app_ctxfinish isc__app_ctxfinish diff --git a/lib/isc/include/isc/platform.h.in b/lib/isc/include/isc/platform.h.in index 69f81e0af11ac..667a1454a4cd4 100644 --- a/lib/isc/include/isc/platform.h.in +++ b/lib/isc/include/isc/platform.h.in @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2010, 2013, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2010, 2013-2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -15,8 +15,6 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: platform.h.in,v 1.56 2010/12/18 01:56:23 each Exp $ */ - #ifndef ISC_PLATFORM_H #define ISC_PLATFORM_H 1 @@ -172,6 +170,16 @@ @ISC_PLATFORM_NEEDSPRINTF@ /*! \brief + * If this system need a modern printf() that format size %z (size_t). + */ +@ISC_PLATFORM_NEEDPRINTF@ + +/*! \brief + * If this system need a modern fprintf() that format size %z (size_t). + */ +@ISC_PLATFORM_NEEDFPRINTF@ + +/*! \brief * The printf format string modifier to use with isc_uint64_t values. */ @ISC_PLATFORM_QUADFORMAT@ diff --git a/lib/isc/include/isc/print.h b/lib/isc/include/isc/print.h index 2b9169001fec9..d7fca7442d575 100644 --- a/lib/isc/include/isc/print.h +++ b/lib/isc/include/isc/print.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2007, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-2001, 2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -15,8 +15,6 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: print.h,v 1.26 2007/06/19 23:47:18 tbox Exp $ */ - #ifndef ISC_PRINT_H #define ISC_PRINT_H 1 @@ -47,6 +45,16 @@ #undef sprintf #endif +#if !defined(ISC_PLATFORM_NEEDFPRINTF) && defined(ISC__PRINT_SOURCE) +#define ISC_PLATFORM_NEEDFPRINTF +#undef fprintf +#endif + +#if !defined(ISC_PLATFORM_NEEDPRINTF) && defined(ISC__PRINT_SOURCE) +#define ISC_PLATFORM_NEEDPRINTF +#undef printf +#endif + /*** *** Macros ***/ @@ -60,10 +68,8 @@ #include <stdarg.h> #include <stddef.h> #endif -#ifdef ISC_PLATFORM_NEEDSPRINTF -#include <stdio.h> -#endif +#include <stdio.h> ISC_LANG_BEGINDECLS @@ -71,20 +77,37 @@ ISC_LANG_BEGINDECLS int isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) ISC_FORMAT_PRINTF(3, 0); +#undef vsnprintf #define vsnprintf isc_print_vsnprintf int isc_print_snprintf(char *str, size_t size, const char *format, ...) ISC_FORMAT_PRINTF(3, 4); +#undef snprintf #define snprintf isc_print_snprintf #endif /* ISC_PLATFORM_NEEDVSNPRINTF */ #ifdef ISC_PLATFORM_NEEDSPRINTF int isc_print_sprintf(char *str, const char *format, ...) ISC_FORMAT_PRINTF(2, 3); +#undef sprintf #define sprintf isc_print_sprintf #endif +#ifdef ISC_PLATFORM_NEEDPRINTF +int +isc_print_printf(const char *format, ...) ISC_FORMAT_PRINTF(1, 2); +#undef printf +#define printf isc_print_printf +#endif + +#ifdef ISC_PLATFORM_NEEDFPRINTF +int +isc_print_fprintf(FILE * fp, const char *format, ...) ISC_FORMAT_PRINTF(2, 3); +#undef fprintf +#define fprintf isc_print_fprintf +#endif + ISC_LANG_ENDDECLS #endif /* ISC_PRINT_H */ diff --git a/lib/isc/include/isc/safe.h b/lib/isc/include/isc/safe.h index 89d56def73fdf..c6a3033525513 100644 --- a/lib/isc/include/isc/safe.h +++ b/lib/isc/include/isc/safe.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2013, 2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -26,9 +26,17 @@ ISC_LANG_BEGINDECLS isc_boolean_t -isc_safe_memcmp(const void *s1, const void *s2, size_t n); +isc_safe_memequal(const void *s1, const void *s2, size_t n); /*%< - * Clone of libc memcmp() safe to differential timing attacks. + * Returns ISC_TRUE iff. two blocks of memory are equal, otherwise + * ISC_FALSE. + * + */ + +int +isc_safe_memcompare(const void *b1, const void *b2, size_t len); +/*%< + * Clone of libc memcmp() which is safe to differential timing attacks. */ ISC_LANG_ENDDECLS diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 0a7799cd6a387..6baf786bdeab5 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007, 2010-2012 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2007, 2010-2012, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -56,6 +56,8 @@ #define ISC_MAX(a, b) ((a) > (b) ? (a) : (b)) #define ISC_MIN(a, b) ((a) < (b) ? (a) : (b)) +#define ISC_CLAMP(v, x, y) ((v) < (x) ? (x) : ((v) > (y) ? (y) : (v))) + /*% * Use this to remove the const qualifier of a variable to assign it to * a non-const variable or pass it as a non-const function argument ... diff --git a/lib/isc/lex.c b/lib/isc/lex.c index aa3a6c9ffd594..ce1c5599412fd 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007, 2013, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2013-2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -41,6 +41,7 @@ typedef struct inputsource { isc_boolean_t is_file; isc_boolean_t need_close; isc_boolean_t at_eof; + isc_boolean_t last_was_eol; isc_buffer_t * pushback; unsigned int ignored; void * input; @@ -202,6 +203,7 @@ new_source(isc_lex_t *lex, isc_boolean_t is_file, isc_boolean_t need_close, source->is_file = is_file; source->need_close = need_close; source->at_eof = ISC_FALSE; + source->last_was_eol = lex->last_was_eol; source->input = input; source->name = isc_mem_strdup(lex->mctx, name); if (source->name == NULL) { @@ -289,6 +291,7 @@ isc_lex_close(isc_lex_t *lex) { return (ISC_R_NOMORE); ISC_LIST_UNLINK(lex->sources, source, link); + lex->last_was_eol = source->last_was_eol; if (source->is_file) { if (source->need_close) (void)fclose((FILE *)(source->input)); diff --git a/lib/isc/lib.c b/lib/isc/lib.c index 0ab72420c2b96..45ae2f36605f6 100644 --- a/lib/isc/lib.c +++ b/lib/isc/lib.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2009, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -29,6 +29,7 @@ #include <isc/mem.h> #include <isc/msgs.h> #include <isc/once.h> +#include <isc/print.h> #include <isc/socket.h> #include <isc/task.h> #include <isc/timer.h> diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 1962245c01c82..854425750bcd2 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -43,6 +43,7 @@ #define ISC_MEM_DEBUGGING 0 #endif LIBISC_EXTERNAL_DATA unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING; +LIBISC_EXTERNAL_DATA unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT; /* * Constants. @@ -215,6 +216,8 @@ struct isc__mempool { static void print_active(isc__mem_t *ctx, FILE *out); +#endif /* ISC_MEM_TRACKLINES */ + /*% * The following can be either static or public, depending on build environment. */ @@ -321,7 +324,6 @@ isc__mem_checkdestroyed(FILE *file); ISC_MEMFUNC_SCOPE unsigned int isc__mem_references(isc_mem_t *ctx0); #endif -#endif /* ISC_MEM_TRACKLINES */ static struct isc__memmethods { isc_memmethods_t methods; @@ -660,7 +662,7 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) { size_t new_size = quantize(size); void *ret; - if (size >= ctx->max_size || new_size >= ctx->max_size) { + if (new_size >= ctx->max_size) { /* * memget() was called on something beyond our upper limit. */ @@ -740,7 +742,7 @@ static inline void mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size) { size_t new_size = quantize(size); - if (size == ctx->max_size || new_size >= ctx->max_size) { + if (new_size >= ctx->max_size) { /* * memput() called on something beyond our upper limit. */ @@ -896,7 +898,7 @@ isc__mem_createx(size_t init_max_size, size_t target_size, isc_mem_t **ctxp) { return (isc__mem_createx2(init_max_size, target_size, memalloc, memfree, - arg, ctxp, ISC_MEMFLAG_DEFAULT)); + arg, ctxp, isc_mem_defaultflags)); } @@ -1038,7 +1040,7 @@ ISC_MEMFUNC_SCOPE isc_result_t isc__mem_create(size_t init_max_size, size_t target_size, isc_mem_t **ctxp) { return (isc__mem_createx2(init_max_size, target_size, default_memalloc, default_memfree, NULL, - ctxp, ISC_MEMFLAG_DEFAULT)); + ctxp, isc_mem_defaultflags)); } ISC_MEMFUNC_SCOPE isc_result_t @@ -1092,11 +1094,17 @@ destroy(isc__mem_t *ctx) { if (ctx->checkfree) { for (i = 0; i <= ctx->max_size; i++) { + if (ctx->stats[i].gets != 0U) { + fprintf(stderr, + "Failing assertion due to probable " + "leaked memory in context %p (\"%s\") " + "(stats[%u].gets == %lu).\n", + ctx, ctx->name, i, ctx->stats[i].gets); #if ISC_MEM_TRACKLINES - if (ctx->stats[i].gets != 0U) print_active(ctx, stderr); #endif - INSIST(ctx->stats[i].gets == 0U); + INSIST(ctx->stats[i].gets == 0U); + } } } @@ -1286,13 +1294,10 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) { } ADD_TRACE(ctx, ptr, size, file, line); - if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water && - !ctx->is_overmem) { + if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water) { ctx->is_overmem = ISC_TRUE; - } - if (ctx->hi_water != 0U && !ctx->hi_called && - ctx->inuse > ctx->hi_water) { - call_water = ISC_TRUE; + if (!ctx->hi_called) + call_water = ISC_TRUE; } if (ctx->inuse > ctx->maxinuse) { ctx->maxinuse = ctx->inuse; @@ -1303,7 +1308,7 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) { } MCTXUNLOCK(ctx, &ctx->lock); - if (call_water) + if (call_water && (ctx->water != NULL)) (ctx->water)(ctx->water_arg, ISC_MEM_HIWATER); return (ptr); @@ -1347,18 +1352,15 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { * when the context was pushed over hi_water but then had * isc_mem_setwater() called with 0 for hi_water and lo_water. */ - if (ctx->is_overmem && - (ctx->inuse < ctx->lo_water || ctx->lo_water == 0U)) { + if ((ctx->inuse < ctx->lo_water) || (ctx->lo_water == 0U)) { ctx->is_overmem = ISC_FALSE; - } - if (ctx->hi_called && - (ctx->inuse < ctx->lo_water || ctx->lo_water == 0U)) { - if (ctx->water != NULL) + if (ctx->hi_called) call_water = ISC_TRUE; } + MCTXUNLOCK(ctx, &ctx->lock); - if (call_water) + if (call_water && (ctx->water != NULL)) (ctx->water)(ctx->water_arg, ISC_MEM_LOWATER); } @@ -1411,8 +1413,8 @@ print_active(isc__mem_t *mctx, FILE *out) { } } if (!found) - fprintf(out, "%s", isc_msgcat_get(isc_msgcat, ISC_MSGSET_MEM, - ISC_MSG_NONE, "\tNone.\n")); + fputs(isc_msgcat_get(isc_msgcat, ISC_MSGSET_MEM, + ISC_MSG_NONE, "\tNone.\n"), out); } } #endif @@ -1534,15 +1536,10 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) { REQUIRE(VALID_CONTEXT(ctx)); - if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { - MCTXLOCK(ctx, &ctx->lock); - si = isc__mem_allocateunlocked((isc_mem_t *)ctx, size); - } else { - si = isc__mem_allocateunlocked((isc_mem_t *)ctx, size); - MCTXLOCK(ctx, &ctx->lock); - if (si != NULL) - mem_getstats(ctx, si[-1].u.size); - } + MCTXLOCK(ctx, &ctx->lock); + si = isc__mem_allocateunlocked((isc_mem_t *)ctx, size); + if (((ctx->flags & ISC_MEMFLAG_INTERNAL) == 0) && (si != NULL)) + mem_getstats(ctx, si[-1].u.size); #if ISC_MEM_TRACKLINES ADD_TRACE(ctx, si, si[-1].u.size, file, line); @@ -1767,7 +1764,6 @@ isc__mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg, ctx->water_arg = NULL; ctx->hi_water = 0; ctx->lo_water = 0; - ctx->hi_called = ISC_FALSE; } else { if (ctx->hi_called && (ctx->water != water || ctx->water_arg != water_arg || diff --git a/lib/isc/pool.c b/lib/isc/pool.c index 509abcb418d48..fe25cb472d737 100644 --- a/lib/isc/pool.c +++ b/lib/isc/pool.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2013, 2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -70,7 +70,7 @@ alloc_pool(isc_mem_t *mctx, unsigned int count, isc_pool_t **poolp) { isc_result_t isc_pool_create(isc_mem_t *mctx, unsigned int count, - isc_pooldeallocator_t free, + isc_pooldeallocator_t release, isc_poolinitializer_t init, void *initarg, isc_pool_t **poolp) { @@ -85,7 +85,7 @@ isc_pool_create(isc_mem_t *mctx, unsigned int count, if (result != ISC_R_SUCCESS) return (result); - pool->free = free; + pool->free = release; pool->init = init; pool->initarg = initarg; diff --git a/lib/isc/print.c b/lib/isc/print.c index 06719e83a5477..21b9096c1076c 100644 --- a/lib/isc/print.c +++ b/lib/isc/print.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2008, 2010, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2008, 2010, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-2001, 2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -15,8 +15,6 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: print.c,v 1.37 2010/10/18 23:47:08 tbox Exp $ */ - /*! \file */ #include <config.h> @@ -24,6 +22,7 @@ #include <ctype.h> #include <stdio.h> /* for sprintf() */ #include <string.h> /* for strlen() */ +#include <assert.h> /* for assert() */ #define ISC__PRINT_SOURCE /* Used to get the isc_print_* prototypes. */ @@ -34,14 +33,79 @@ #include <isc/stdlib.h> #include <isc/util.h> +/* + * We use the system's sprintf so we undef it here. + */ +#undef sprintf + +static int +isc__print_printf(void (*emit)(char, void *), void *arg, + const char *format, va_list ap); + +static void +file_emit(char c, void *arg) { + FILE *fp = arg; + int i = c & 0xff; + + putc(i, fp); +} + +#if 0 +static int +isc_print_vfprintf(FILE *fp, const char *format, va_list ap) { + assert(fp != NULL); + assert(format != NULL); + + return (isc__print_printf(file_emit, fp, format, ap)); +} +#endif + +int +isc_print_printf(const char *format, ...) { + va_list ap; + int n; + + assert(format != NULL); + + va_start(ap, format); + n = isc__print_printf(file_emit, stdout, format, ap); + va_end(ap); + return (n); +} + +int +isc_print_fprintf(FILE *fp, const char *format, ...) { + va_list ap; + int n; + + assert(fp != NULL); + assert(format != NULL); + + va_start(ap, format); + n = isc__print_printf(file_emit, fp, format, ap); + va_end(ap); + return (n); +} + +static void +nocheck_emit(char c, void *arg) { + struct { char *str; } *a = arg; + + *(a->str)++ = c; +} + int isc_print_sprintf(char *str, const char *format, ...) { + struct { char *str; } arg; + int n; va_list ap; + arg.str = str; + va_start(ap, format); - vsprintf(str, format, ap); + n = isc__print_printf(nocheck_emit, &arg, format, ap); va_end(ap); - return (strlen(str)); + return (n); } /*! @@ -54,7 +118,7 @@ isc_print_snprintf(char *str, size_t size, const char *format, ...) { int ret; va_start(ap, format); - ret = vsnprintf(str, size, format, ap); + ret = isc_print_vsnprintf(str, size, format, ap); va_end(ap); return (ret); @@ -64,10 +128,40 @@ isc_print_snprintf(char *str, size_t size, const char *format, ...) { * Return length of string that would have been written if not truncated. */ +static void +string_emit(char c, void *arg) { + struct { char *str; size_t size; } *p = arg; + + if (p->size > 0U) { + *(p->str)++ = c; + p->size--; + } +} + int isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { + struct { char *str; size_t size; } arg; + int n; + + assert(str != NULL); + assert(format != NULL); + + arg.str = str; + arg.size = size; + + n = isc__print_printf(string_emit, &arg, format, ap); + if (arg.size > 0U) + *arg.str = '\0'; + return (n); +} + +static int +isc__print_printf(void (*emit)(char, void *), void *arg, + const char *format, va_list ap) +{ int h; int l; + int z; int q; int alt; int zero; @@ -83,7 +177,6 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { char buf[1024]; char c; void *v; - char *save = str; const char *cp; const char *head; int count = 0; @@ -91,22 +184,20 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { int zeropad; int dot; double dbl; + isc_boolean_t precision_set; #ifdef HAVE_LONG_DOUBLE long double ldbl; #endif char fmt[32]; - INSIST(str != NULL); - INSIST(format != NULL); + assert(emit != NULL); + assert(arg != NULL); + assert(format != NULL); while (*format != '\0') { if (*format != '%') { - if (size > 1) { - *str++ = *format; - size--; - } + emit(*format++, arg); count++; - format++; continue; } format++; @@ -114,10 +205,11 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { /* * Reset flags. */ - dot = neg = space = plus = left = zero = alt = h = l = q = 0; + dot = neg = space = plus = left = zero = alt = h = l = q = z = 0; width = precision = 0; head = ""; pad = zeropad = 0; + precision_set = ISC_FALSE; do { if (*format == '#') { @@ -163,10 +255,12 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { dot = 1; if (*format == '*') { precision = va_arg(ap, int); + precision_set = ISC_TRUE; format++; } else if (isdigit((unsigned char)*format)) { char *e; precision = strtoul(format, &e, 10); + precision_set = ISC_TRUE; format = e; } } @@ -175,10 +269,7 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { case '\0': continue; case '%': - if (size > 1) { - *str++ = *format; - size--; - } + emit(*format, arg); count++; break; case 'q': @@ -197,6 +288,10 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { format++; } goto doint; + case 'z': + z = 1; + format++; + goto doint; case 'n': case 'i': case 'd': @@ -205,25 +300,30 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { case 'x': case 'X': doint: - if (precision != 0) + if (precision != 0U) zero = 0; switch (*format) { case 'n': if (h) { short int *p; p = va_arg(ap, short *); - REQUIRE(p != NULL); - *p = str - save; + assert(p != NULL); + *p = count; } else if (l) { long int *p; p = va_arg(ap, long *); - REQUIRE(p != NULL); - *p = str - save; + assert(p != NULL); + *p = count; + } else if (z) { + size_t *p; + p = va_arg(ap, size_t *); + assert(p != NULL); + *p = count; } else { int *p; p = va_arg(ap, int *); - REQUIRE(p != NULL); - *p = str - save; + assert(p != NULL); + *p = count; } break; case 'i': @@ -232,6 +332,8 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpi = va_arg(ap, isc_int64_t); else if (l) tmpi = va_arg(ap, long int); + else if (z) + tmpi = va_arg(ap, ssize_t); else tmpi = va_arg(ap, int); if (tmpi < 0) { @@ -257,12 +359,14 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpui /= 1000000000; mid = tmpui % 1000000000; hi = tmpui / 1000000000; - if (hi != 0) + if (hi != 0U) { sprintf(buf, "%lu", hi); - else - buf[0] = '\0'; - sprintf(buf + strlen(buf), "%lu", mid); - sprintf(buf + strlen(buf), "%lu", lo); + sprintf(buf + strlen(buf), + "%09lu", mid); + } else + sprintf(buf, "%lu", mid); + sprintf(buf + strlen(buf), "%09lu", + lo); } goto printint; case 'o': @@ -270,6 +374,8 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpui = va_arg(ap, isc_uint64_t); else if (l) tmpui = va_arg(ap, long int); + else if (z) + tmpui = va_arg(ap, size_t); else tmpui = va_arg(ap, int); if (tmpui <= 0xffffffffU) @@ -283,17 +389,17 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpui /= 010000000000; mid = tmpui % 010000000000; hi = tmpui / 010000000000; - if (hi != 0) { + if (hi != 0U) { sprintf(buf, alt ? "%#lo" : "%lo", hi); sprintf(buf + strlen(buf), - "%lo", mid); + "%09lo", mid); } else sprintf(buf, alt ? "%#lo" : "%lo", mid); - sprintf(buf + strlen(buf), "%lo", lo); + sprintf(buf + strlen(buf), "%09lo", lo); } goto printint; case 'u': @@ -301,6 +407,8 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpui = va_arg(ap, isc_uint64_t); else if (l) tmpui = va_arg(ap, unsigned long int); + else if (z) + tmpui = va_arg(ap, size_t); else tmpui = va_arg(ap, unsigned int); if (tmpui <= 0xffffffffU) @@ -314,12 +422,14 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpui /= 1000000000; mid = tmpui % 1000000000; hi = tmpui / 1000000000; - if (hi != 0) + if (hi != 0U) { sprintf(buf, "%lu", hi); - else - buf[0] = '\0'; - sprintf(buf + strlen(buf), "%lu", mid); - sprintf(buf + strlen(buf), "%lu", lo); + sprintf(buf + strlen(buf), + "%09lu", mid); + } else + sprintf(buf, "%lu", mid); + sprintf(buf + strlen(buf), "%09lu", + lo); } goto printint; case 'x': @@ -327,11 +437,13 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpui = va_arg(ap, isc_uint64_t); else if (l) tmpui = va_arg(ap, unsigned long int); + else if (z) + tmpui = va_arg(ap, size_t); else tmpui = va_arg(ap, unsigned int); if (alt) { head = "0x"; - if (precision > 2) + if (precision > 2U) precision -= 2; } if (tmpui <= 0xffffffffU) @@ -341,7 +453,7 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { unsigned long hi = tmpui>>32; unsigned long lo = tmpui & 0xffffffff; sprintf(buf, "%lx", hi); - sprintf(buf + strlen(buf), "%lx", lo); + sprintf(buf + strlen(buf), "%08lx", lo); } goto printint; case 'X': @@ -349,11 +461,13 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpui = va_arg(ap, isc_uint64_t); else if (l) tmpui = va_arg(ap, unsigned long int); + else if (z) + tmpui = va_arg(ap, size_t); else tmpui = va_arg(ap, unsigned int); if (alt) { head = "0X"; - if (precision > 2) + if (precision > 2U) precision -= 2; } if (tmpui <= 0xffffffffU) @@ -363,17 +477,17 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { unsigned long hi = tmpui>>32; unsigned long lo = tmpui & 0xffffffff; sprintf(buf, "%lX", hi); - sprintf(buf + strlen(buf), "%lX", lo); + sprintf(buf + strlen(buf), "%08lX", lo); } goto printint; printint: - if (precision != 0 || width != 0) { + if (precision_set || width != 0U) { length = strlen(buf); if (length < precision) zeropad = precision - length; else if (length < width && zero) zeropad = width - length; - if (width != 0) { + if (width != 0U) { pad = width - length - zeropad - strlen(head); if (pad < 0) @@ -383,30 +497,23 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { count += strlen(head) + strlen(buf) + pad + zeropad; if (!left) { - while (pad > 0 && size > 1) { - *str++ = ' '; - size--; + while (pad > 0) { + emit(' ', arg); pad--; } } cp = head; - while (*cp != '\0' && size > 1) { - *str++ = *cp++; - size--; - } - while (zeropad > 0 && size > 1) { - *str++ = '0'; - size--; + while (*cp != '\0') + emit(*cp++, arg); + while (zeropad > 0) { + emit('0', arg); zeropad--; } cp = buf; - while (*cp != '\0' && size > 1) { - *str++ = *cp++; - size--; - } - while (pad > 0 && size > 1) { - *str++ = ' '; - size--; + while (*cp != '\0') + emit(*cp++, arg); + while (pad > 0) { + emit(' ', arg); pad--; } break; @@ -416,76 +523,63 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { break; case 's': cp = va_arg(ap, char *); - REQUIRE(cp != NULL); - if (precision != 0) { + if (precision_set) { /* * cp need not be NULL terminated. */ const char *tp; unsigned long n; + if (precision != 0U) + assert(cp != NULL); n = precision; tp = cp; - while (n != 0 && *tp != '\0') + while (n != 0U && *tp != '\0') n--, tp++; length = precision - n; } else { + assert(cp != NULL); length = strlen(cp); } - if (width != 0) { + if (width != 0U) { pad = width - length; if (pad < 0) pad = 0; } count += pad + length; if (!left) - while (pad > 0 && size > 1) { - *str++ = ' '; - size--; + while (pad > 0) { + emit(' ', arg); pad--; } - if (precision != 0) - while (precision > 0 && *cp != '\0' && - size > 1) { - *str++ = *cp++; - size--; + if (precision_set) + while (precision > 0U && *cp != '\0') { + emit(*cp++, arg); precision--; } else - while (*cp != '\0' && size > 1) { - *str++ = *cp++; - size--; - } - while (pad > 0 && size > 1) { - *str++ = ' '; - size--; + while (*cp != '\0') + emit(*cp++, arg); + while (pad > 0) { + emit(' ', arg); pad--; } break; case 'c': c = va_arg(ap, int); - if (width > 0) { + if (width > 0U) { count += width; width--; - if (left && size > 1) { - *str++ = c; - size--; - } - while (width-- > 0 && size > 1) { - *str++ = ' '; - size--; - } - if (!left && size > 1) { - *str++ = c; - size--; - } + if (left) + emit(c, arg); + while (width-- > 0U) + emit(' ', arg); + if (!left) + emit(c, arg); } else { count++; - if (size > 1) { - *str++ = c; - size--; - } + emit(c, arg); } break; case 'p': @@ -494,57 +588,46 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { length = strlen(buf); if (precision > length) zeropad = precision - length; - if (width > 0) { + if (width > 0U) { pad = width - length - zeropad; if (pad < 0) pad = 0; } count += length + pad + zeropad; if (!left) - while (pad > 0 && size > 1) { - *str++ = ' '; - size--; + while (pad > 0) { + emit(' ', arg); pad--; } cp = buf; if (zeropad > 0 && buf[0] == '0' && (buf[1] == 'x' || buf[1] == 'X')) { - if (size > 1) { - *str++ = *cp++; - size--; - } - if (size > 1) { - *str++ = *cp++; - size--; - } - while (zeropad > 0 && size > 1) { - *str++ = '0'; - size--; + emit(*cp++, arg); + emit(*cp++, arg); + while (zeropad > 0) { + emit('0', arg); zeropad--; } } - while (*cp != '\0' && size > 1) { - *str++ = *cp++; - size--; - } - while (pad > 0 && size > 1) { - *str++ = ' '; - size--; + while (*cp != '\0') + emit(*cp++, arg); + while (pad > 0) { + emit(' ', arg); pad--; } break; case 'D': /*deprecated*/ - INSIST("use %ld instead of %D" == NULL); + assert("use %ld instead of %D" == NULL); case 'O': /*deprecated*/ - INSIST("use %lo instead of %O" == NULL); + assert("use %lo instead of %O" == NULL); case 'U': /*deprecated*/ - INSIST("use %lu instead of %U" == NULL); + assert("use %lu instead of %U" == NULL); case 'L': #ifdef HAVE_LONG_DOUBLE l = 1; #else - INSIST("long doubles are not supported" == NULL); + assert("long doubles are not supported" == NULL); #endif /*FALLTHROUGH*/ case 'e': @@ -564,7 +647,7 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { * if we cap the precision at 512 we will not * overflow buf. */ - if (precision > 512) + if (precision > 512U) precision = 512; sprintf(fmt, "%%%s%s.%lu%s%c", alt ? "#" : "", plus ? "+" : space ? " " : "", @@ -586,26 +669,22 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { sprintf(buf, fmt, dbl); } length = strlen(buf); - if (width > 0) { + if (width > 0U) { pad = width - length; if (pad < 0) pad = 0; } count += length + pad; if (!left) - while (pad > 0 && size > 1) { - *str++ = ' '; - size--; + while (pad > 0) { + emit(' ', arg); pad--; } cp = buf; - while (*cp != ' ' && size > 1) { - *str++ = *cp++; - size--; - } - while (pad > 0 && size > 1) { - *str++ = ' '; - size--; + while (*cp != ' ') + emit(*cp++, arg); + while (pad > 0) { + emit(' ', arg); pad--; } break; @@ -618,7 +697,5 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { } format++; } - if (size > 0) - *str = '\0'; return (count); } diff --git a/lib/isc/pthreads/mutex.c b/lib/isc/pthreads/mutex.c index c7e5795b6807a..0ee37d28bbfed 100644 --- a/lib/isc/pthreads/mutex.c +++ b/lib/isc/pthreads/mutex.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007, 2008, 2011, 2012 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2008, 2011, 2012, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2000-2002 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -28,6 +28,7 @@ #include <isc/mutex.h> #include <isc/util.h> +#include <isc/print.h> #include <isc/strerror.h> #if ISC_MUTEX_PROFILE diff --git a/lib/isc/regex.c b/lib/isc/regex.c index 2ee13653bdde5..a1e76c7591800 100644 --- a/lib/isc/regex.c +++ b/lib/isc/regex.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,6 +17,7 @@ #include <config.h> #include <isc/file.h> +#include <isc/print.h> #include <isc/regex.h> #include <isc/string.h> diff --git a/lib/isc/rwlock.c b/lib/isc/rwlock.c index 9c84c258a28b1..461d6e295a779 100644 --- a/lib/isc/rwlock.c +++ b/lib/isc/rwlock.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2001, 2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -27,6 +27,7 @@ #include <isc/magic.h> #include <isc/msgs.h> #include <isc/platform.h> +#include <isc/print.h> #include <isc/rwlock.h> #include <isc/util.h> diff --git a/lib/isc/safe.c b/lib/isc/safe.c index fd27687188722..8ac4a5b9193fa 100644 --- a/lib/isc/safe.c +++ b/lib/isc/safe.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2013, 2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -14,8 +14,6 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id$ */ - /*! \file */ #include <config.h> @@ -28,7 +26,7 @@ #endif isc_boolean_t -isc_safe_memcmp(const void *s1, const void *s2, size_t n) { +isc_safe_memequal(const void *s1, const void *s2, size_t n) { isc_uint8_t acc = 0; if (n != 0U) { @@ -40,3 +38,30 @@ isc_safe_memcmp(const void *s1, const void *s2, size_t n) { } return (ISC_TF(acc == 0)); } + + +int +isc_safe_memcompare(const void *b1, const void *b2, size_t len) { + const unsigned char *p1 = b1, *p2 = b2; + size_t i; + int res = 0, done = 0; + + for (i = 0; i < len; i++) { + /* lt is -1 if p1[i] < p2[i]; else 0. */ + int lt = (p1[i] - p2[i]) >> CHAR_BIT; + + /* gt is -1 if p1[i] > p2[i]; else 0. */ + int gt = (p2[i] - p1[i]) >> CHAR_BIT; + + /* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */ + int cmp = lt - gt; + + /* set res = cmp if !done. */ + res |= cmp & ~done; + + /* set done if p1[i] != p2[i]. */ + done |= lt | gt; + } + + return (res); +} diff --git a/lib/isc/socket_api.c b/lib/isc/socket_api.c index dca6c34fc37a4..cfe2886f82d1b 100644 --- a/lib/isc/socket_api.c +++ b/lib/isc/socket_api.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2009, 2011, 2012, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -210,10 +210,10 @@ isc_socket_gettype(isc_socket_t *sock) { } void -isc_socket_setname(isc_socket_t *socket, const char *name, void *tag) { - REQUIRE(ISCAPI_SOCKET_VALID(socket)); +isc_socket_setname(isc_socket_t *sock, const char *name, void *tag) { + REQUIRE(ISCAPI_SOCKET_VALID(sock)); - UNUSED(socket); /* in case REQUIRE() is empty */ + UNUSED(sock); /* in case REQUIRE() is empty */ UNUSED(name); UNUSED(tag); } diff --git a/lib/isc/stats.c b/lib/isc/stats.c index 89e34b3780873..03d2a8a7d103d 100644 --- a/lib/isc/stats.c +++ b/lib/isc/stats.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2012, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2009, 2012, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -169,19 +169,22 @@ isc_stats_detach(isc_stats_t **statsp) { LOCK(&stats->lock); stats->references--; - UNLOCK(&stats->lock); if (stats->references == 0) { isc_mem_put(stats->mctx, stats->copiedcounters, sizeof(isc_stat_t) * stats->ncounters); isc_mem_put(stats->mctx, stats->counters, sizeof(isc_stat_t) * stats->ncounters); + UNLOCK(&stats->lock); DESTROYLOCK(&stats->lock); #ifdef ISC_RWLOCK_USEATOMIC isc_rwlock_destroy(&stats->counterlock); #endif isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats)); + return; } + + UNLOCK(&stats->lock); } int diff --git a/lib/isc/task.c b/lib/isc/task.c index 02d6e2abaf60a..3503801e4517e 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2012, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2012, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -34,6 +34,7 @@ #include <isc/mem.h> #include <isc/msgs.h> #include <isc/platform.h> +#include <isc/print.h> #include <isc/string.h> #include <isc/task.h> #include <isc/thread.h> @@ -156,6 +157,13 @@ struct isc__taskmgr { isc_boolean_t pause_requested; isc_boolean_t exclusive_requested; isc_boolean_t exiting; + + /* + * Multiple threads can read/write 'excl' at the same time, so we need + * to protect the access. We can't use 'lock' since isc_task_detach() + * will try to acquire it. + */ + isc_mutex_t excl_lock; isc__task_t *excl; #ifdef USE_SHARED_MANAGER unsigned int refs; @@ -1307,6 +1315,7 @@ manager_free(isc__taskmgr_t *manager) { isc_mem_free(manager->mctx, manager->threads); #endif /* USE_WORKER_THREADS */ DESTROYLOCK(&manager->lock); + DESTROYLOCK(&manager->excl_lock); manager->common.impmagic = 0; manager->common.magic = 0; mctx = manager->mctx; @@ -1359,6 +1368,11 @@ isc__taskmgr_create(isc_mem_t *mctx, unsigned int workers, result = isc_mutex_init(&manager->lock); if (result != ISC_R_SUCCESS) goto cleanup_mgr; + result = isc_mutex_init(&manager->excl_lock); + if (result != ISC_R_SUCCESS) { + DESTROYLOCK(&manager->lock); + goto cleanup_mgr; + } #ifdef USE_WORKER_THREADS manager->workers = 0; @@ -1490,8 +1504,10 @@ isc__taskmgr_destroy(isc_taskmgr_t **managerp) { /* * Detach the exclusive task before acquiring the manager lock */ + LOCK(&manager->excl_lock); if (manager->excl != NULL) isc__task_detach((isc_task_t **) &manager->excl); + UNLOCK(&manager->excl_lock); /* * Unlike elsewhere, we're going to hold this lock a long time. @@ -1650,23 +1666,29 @@ isc__taskmgr_setexcltask(isc_taskmgr_t *mgr0, isc_task_t *task0) { REQUIRE(VALID_MANAGER(mgr)); REQUIRE(VALID_TASK(task)); + LOCK(&mgr->excl_lock); if (mgr->excl != NULL) isc__task_detach((isc_task_t **) &mgr->excl); isc__task_attach(task0, (isc_task_t **) &mgr->excl); + UNLOCK(&mgr->excl_lock); } ISC_TASKFUNC_SCOPE isc_result_t isc__taskmgr_excltask(isc_taskmgr_t *mgr0, isc_task_t **taskp) { isc__taskmgr_t *mgr = (isc__taskmgr_t *) mgr0; + isc_result_t result = ISC_R_SUCCESS; REQUIRE(VALID_MANAGER(mgr)); REQUIRE(taskp != NULL && *taskp == NULL); - if (mgr->excl == NULL) - return (ISC_R_NOTFOUND); + LOCK(&mgr->excl_lock); + if (mgr->excl != NULL) + isc__task_attach((isc_task_t *) mgr->excl, taskp); + else + result = ISC_R_NOTFOUND; + UNLOCK(&mgr->excl_lock); - isc__task_attach((isc_task_t *) mgr->excl, taskp); - return (ISC_R_SUCCESS); + return (result); } ISC_TASKFUNC_SCOPE isc_result_t diff --git a/lib/isc/timer.c b/lib/isc/timer.c index f48259dddbccd..773dacf749354 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007-2009, 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007-2009, 2011, 2012, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2002 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -28,6 +28,7 @@ #include <isc/mem.h> #include <isc/msgs.h> #include <isc/platform.h> +#include <isc/print.h> #include <isc/task.h> #include <isc/thread.h> #include <isc/time.h> diff --git a/lib/isc/unix/app.c b/lib/isc/unix/app.c index aeebc31f9a431..141e9c21a94c7 100644 --- a/lib/isc/unix/app.c +++ b/lib/isc/unix/app.c @@ -90,6 +90,7 @@ ISC_APPFUNC_SCOPE isc_result_t isc__app_onrun(isc_mem_t *mctx, void *arg); ISC_APPFUNC_SCOPE isc_result_t isc__app_ctxrun(isc_appctx_t *ctx); ISC_APPFUNC_SCOPE isc_result_t isc__app_run(void); +ISC_APPFUNC_SCOPE isc_boolean_t isc__app_isrunning(void); ISC_APPFUNC_SCOPE isc_result_t isc__app_ctxshutdown(isc_appctx_t *ctx); ISC_APPFUNC_SCOPE isc_result_t isc__app_shutdown(void); ISC_APPFUNC_SCOPE isc_result_t isc__app_reload(void); @@ -145,6 +146,7 @@ typedef struct isc__appctx { } isc__appctx_t; static isc__appctx_t isc_g_appctx; +static isc_boolean_t is_running = ISC_FALSE; static struct { isc_appmethods_t methods; @@ -154,7 +156,8 @@ static struct { */ #ifndef BIND9 void *run, *shutdown, *start, *onrun, - *reload, *finish, *block, *unblock; + *reload, *finish, *block, *unblock, + *isrunning; #endif } appmethods = { { @@ -174,7 +177,7 @@ static struct { (void *)isc__app_run, (void *)isc__app_shutdown, (void *)isc__app_start, (void *)isc__app_onrun, (void *)isc__app_reload, (void *)isc__app_finish, (void *)isc__app_block, - (void *)isc__app_unblock + (void *)isc__app_unblock, (void *)isc__app_isrunning #endif }; @@ -701,7 +704,7 @@ isc__app_ctxrun(isc_appctx_t *ctx0) { return (ISC_R_UNEXPECTED); } #endif - result = sigsuspend(&sset); + (void)sigsuspend(&sset); #endif /* HAVE_SIGWAIT */ if (ctx->want_reload) { @@ -728,7 +731,18 @@ isc__app_ctxrun(isc_appctx_t *ctx0) { ISC_APPFUNC_SCOPE isc_result_t isc__app_run(void) { - return (isc__app_ctxrun((isc_appctx_t *)&isc_g_appctx)); + isc_result_t result; + + is_running = ISC_TRUE; + result = isc__app_ctxrun((isc_appctx_t *)&isc_g_appctx); + is_running = ISC_FALSE; + + return (result); +} + +ISC_APPFUNC_SCOPE isc_boolean_t +isc__app_isrunning(void) { + return (is_running); } ISC_APPFUNC_SCOPE isc_result_t diff --git a/lib/isc/unix/file.c b/lib/isc/unix/file.c index 1b7d563d875a1..c2abd440e18cd 100644 --- a/lib/isc/unix/file.c +++ b/lib/isc/unix/file.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007, 2009, 2011-2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2009, 2011-2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2000-2002 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -135,12 +135,12 @@ isc_file_mode(const char *file, mode_t *modep) { } isc_result_t -isc_file_getmodtime(const char *file, isc_time_t *time) { +isc_file_getmodtime(const char *file, isc_time_t *modtime) { isc_result_t result; struct stat stats; REQUIRE(file != NULL); - REQUIRE(time != NULL); + REQUIRE(modtime != NULL); result = file_stats(file, &stats); @@ -149,16 +149,16 @@ isc_file_getmodtime(const char *file, isc_time_t *time) { * XXXDCL some operating systems provide nanoseconds, too, * such as BSD/OS via st_mtimespec. */ - isc_time_set(time, stats.st_mtime, 0); + isc_time_set(modtime, stats.st_mtime, 0); return (result); } isc_result_t -isc_file_settime(const char *file, isc_time_t *time) { +isc_file_settime(const char *file, isc_time_t *when) { struct timeval times[2]; - REQUIRE(file != NULL && time != NULL); + REQUIRE(file != NULL && when != NULL); /* * tv_sec is at least a 32 bit quantity on all platforms we're @@ -170,7 +170,7 @@ isc_file_settime(const char *file, isc_time_t *time) { * * isc_time_seconds is changed to be > 32 bits but long is 32 bits * and isc_time_seconds has at least 33 significant bits. */ - times[0].tv_sec = times[1].tv_sec = (long)isc_time_seconds(time); + times[0].tv_sec = times[1].tv_sec = (long)isc_time_seconds(when); /* * Here is the real check for the high bit being set. @@ -186,7 +186,7 @@ isc_file_settime(const char *file, isc_time_t *time) { * we can at least cast to signed so the IRIX compiler shuts up. */ times[0].tv_usec = times[1].tv_usec = - (isc_int32_t)(isc_time_nanoseconds(time) / 1000); + (isc_int32_t)(isc_time_nanoseconds(when) / 1000); if (utimes(file, times) < 0) return (isc__errno2result(errno)); diff --git a/lib/isc/unix/ifiter_ioctl.c b/lib/isc/unix/ifiter_ioctl.c index f0026c285b804..6b1ceda09e0a0 100644 --- a/lib/isc/unix/ifiter_ioctl.c +++ b/lib/isc/unix/ifiter_ioctl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2009, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2009, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -17,6 +17,8 @@ /* $Id: ifiter_ioctl.c,v 1.62 2009/01/18 23:48:14 tbox Exp $ */ +#include <isc/print.h> + /*! \file * \brief * Obtain the list of network interfaces using the SIOCGLIFCONF ioctl. diff --git a/lib/isc/unix/ifiter_sysctl.c b/lib/isc/unix/ifiter_sysctl.c index 102ecc1fee289..e4ca48a9aa4e4 100644 --- a/lib/isc/unix/ifiter_sysctl.c +++ b/lib/isc/unix/ifiter_sysctl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -30,6 +30,8 @@ #include <net/route.h> #include <net/if_dl.h> +#include <isc/print.h> + /* XXX what about Alpha? */ #ifdef sgi #define ROUNDUP(a) ((a) > 0 ? \ diff --git a/lib/isc/unix/net.c b/lib/isc/unix/net.c index e4de0489ec113..c811d1ba4194d 100644 --- a/lib/isc/unix/net.c +++ b/lib/isc/unix/net.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007, 2008, 2012, 2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2008, 2012, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -414,12 +414,12 @@ getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) { sysctlname_lowport = SYSCTL_V6PORTRANGE_LOW; sysctlname_hiport = SYSCTL_V6PORTRANGE_HIGH; } - portlen = sizeof(portlen); + portlen = sizeof(port_low); if (sysctlbyname(sysctlname_lowport, &port_low, &portlen, NULL, 0) < 0) { return (ISC_R_FAILURE); } - portlen = sizeof(portlen); + portlen = sizeof(port_high); if (sysctlbyname(sysctlname_hiport, &port_high, &portlen, NULL, 0) < 0) { return (ISC_R_FAILURE); @@ -453,12 +453,12 @@ getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) { miblen = sizeof(mib_lo6) / sizeof(mib_lo6[0]); } - portlen = sizeof(portlen); + portlen = sizeof(port_low); if (sysctl(mib_lo, miblen, &port_low, &portlen, NULL, 0) < 0) { return (ISC_R_FAILURE); } - portlen = sizeof(portlen); + portlen = sizeof(port_high); if (sysctl(mib_hi, miblen, &port_high, &portlen, NULL, 0) < 0) { return (ISC_R_FAILURE); } @@ -477,11 +477,34 @@ getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) { isc_result_t isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high) { int result = ISC_R_FAILURE; +#if !defined(USE_SYSCTL_PORTRANGE) && defined(__linux) + FILE *fp; +#endif REQUIRE(low != NULL && high != NULL); #if defined(USE_SYSCTL_PORTRANGE) result = getudpportrange_sysctl(af, low, high); +#elif defined(__linux) + + UNUSED(af); + + /* + * Linux local ports are address family agnostic. + */ + fp = fopen("/proc/sys/net/ipv4/ip_local_port_range", "r"); + if (fp != NULL) { + int n; + unsigned int l, h; + + n = fscanf(fp, "%u %u", &l, &h); + if (n == 2 && (l & ~0xffff) == 0 && (h & ~0xffff) == 0) { + *low = l; + *high = h; + result = ISC_R_SUCCESS; + } + fclose(fp); + } #else UNUSED(af); #endif diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 110eafe50fd15..5e6320d821c6a 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2015 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -5957,33 +5957,33 @@ isc__socketmgr_dispatch(isc_socketmgr_t *manager0, isc_socketwait_t *swait) { #ifdef BIND9 void isc__socket_setname(isc_socket_t *socket0, const char *name, void *tag) { - isc__socket_t *socket = (isc__socket_t *)socket0; + isc__socket_t *sock = (isc__socket_t *)socket0; /* - * Name 'socket'. + * Name 'sock'. */ - REQUIRE(VALID_SOCKET(socket)); + REQUIRE(VALID_SOCKET(sock)); - LOCK(&socket->lock); - memset(socket->name, 0, sizeof(socket->name)); - strncpy(socket->name, name, sizeof(socket->name) - 1); - socket->tag = tag; - UNLOCK(&socket->lock); + LOCK(&sock->lock); + memset(sock->name, 0, sizeof(sock->name)); + strncpy(sock->name, name, sizeof(sock->name) - 1); + sock->tag = tag; + UNLOCK(&sock->lock); } ISC_SOCKETFUNC_SCOPE const char * isc__socket_getname(isc_socket_t *socket0) { - isc__socket_t *socket = (isc__socket_t *)socket0; + isc__socket_t *sock = (isc__socket_t *)socket0; - return (socket->name); + return (sock->name); } void * isc__socket_gettag(isc_socket_t *socket0) { - isc__socket_t *socket = (isc__socket_t *)socket0; + isc__socket_t *sock = (isc__socket_t *)socket0; - return (socket->tag); + return (sock->tag); } #endif /* BIND9 */ @@ -5996,9 +5996,9 @@ isc__socket_register(void) { ISC_SOCKETFUNC_SCOPE int isc__socket_getfd(isc_socket_t *socket0) { - isc__socket_t *socket = (isc__socket_t *)socket0; + isc__socket_t *sock = (isc__socket_t *)socket0; - return ((short) socket->fd); + return ((short) sock->fd); } #if defined(HAVE_LIBXML2) && defined(BIND9) |