From: Dave Hart Date: Wed, 3 Jun 2009 01:35:02 +0000 (+0000) Subject: [Bug 1211] keysdir free()d twice #ifdef DEBUG X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=763d262c1381efad593db5cee9d3ad43f21af605;p=thirdparty%2Fntp.git [Bug 1211] keysdir free()d twice #ifdef DEBUG bk: 4a25d346bEbjMl-AfvuLkEVN5eaRmA --- diff --git a/ChangeLog b/ChangeLog index b922dc5038..f71fba2b41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ * [Bug 1208] decodenetnum() buffer overrun on [ with no ] +* [Bug 1211] keysdir free()d twice #ifdef DEBUG (4.2.5p180) 2009/05/29 Released by Harlan Stenn * [Bug 1200] Enable IPv6 in Windows port * Lose FLAG_FIXPOLL, from Dave Mills. diff --git a/libntp/decodenetnum.c b/libntp/decodenetnum.c index 5d646c377a..f5db29ab42 100644 --- a/libntp/decodenetnum.c +++ b/libntp/decodenetnum.c @@ -25,18 +25,18 @@ decodenetnum( NTP_REQUIRE(strlen(num) < sizeof(name)); if ('[' != num[0]) - np = name; + cp = num; else { cp = num + 1; np = name; while (*cp && ']' != *cp) *np++ = *cp++; *np = 0; - np = name; + cp = name; } memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_NUMERICHOST; - err = getaddrinfo(np, NULL, &hints, &ai); + err = getaddrinfo(cp, NULL, &hints, &ai); if (err != 0) return 0; memcpy(netnum, ai->ai_addr, ai->ai_addrlen); diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 5be1e3af5a..00d4f98e23 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -151,7 +151,7 @@ char default_ntp_signd_socket[] = #else ""; #endif -char *ntp_signd_socket; +char *ntp_signd_socket = default_ntp_signd_socket; #ifdef HAVE_NETINFO struct netinfo_config_state *config_netinfo = NULL; int check_netinfo = 1; @@ -206,7 +206,6 @@ static void call_proto_config_from_list(queue *flag_list, int able_flag); static void init_auth_node(void); static void init_syntax_tree(void); #ifdef DEBUG -static void free_auth_node(void); void free_syntax_tree(void); #endif double *create_dval(double val); @@ -295,37 +294,12 @@ init_auth_node(void) my_config.auth.crypto_cmd_list = NULL; my_config.auth.keys = NULL; my_config.auth.keysdir = NULL; - my_config.auth.ntp_signd_socket = default_ntp_signd_socket; + my_config.auth.ntp_signd_socket = NULL; my_config.auth.request_key = 0; my_config.auth.revoke = 0; my_config.auth.trusted_key_list = NULL; } -#ifdef DEBUG -static void -free_auth_node(void) -{ - DESTROY_QUEUE(my_config.auth.crypto_cmd_list); - - if (my_config.auth.keys) { - free(my_config.auth.keys); - my_config.auth.keys = NULL; - } - - if (my_config.auth.keysdir) { - free(my_config.auth.keysdir); - my_config.auth.keysdir = NULL; - } - - if (my_config.auth.ntp_signd_socket != default_ntp_signd_socket) { - free(my_config.auth.ntp_signd_socket); - my_config.auth.ntp_signd_socket = default_ntp_signd_socket; - } - - DESTROY_QUEUE(my_config.auth.trusted_key_list); -} -#endif /* DEBUG */ - static void init_syntax_tree(void) { @@ -394,8 +368,6 @@ free_syntax_tree(void) DESTROY_QUEUE(my_config.ttl); DESTROY_QUEUE(my_config.trap); DESTROY_QUEUE(my_config.vars); - - free_auth_node(); } #endif /* DEBUG */ @@ -1128,9 +1100,9 @@ config_other_modes(void) static void config_auth(void) { + u_char rankey[9]; struct attr_val *my_val; int *key_val; - u_char rankey[9]; int i; /* Crypto Command */ @@ -1149,13 +1121,16 @@ config_auth(void) if (keysdir != default_keysdir) free(keysdir); keysdir = my_config.auth.keysdir; + my_config.auth.keysdir = NULL; } + /* ntp_signd_socket Command */ if (my_config.auth.ntp_signd_socket) { if (ntp_signd_socket != default_ntp_signd_socket) free(ntp_signd_socket); ntp_signd_socket = my_config.auth.ntp_signd_socket; + my_config.auth.ntp_signd_socket = NULL; } #ifdef OPENSSL @@ -1166,8 +1141,11 @@ config_auth(void) #endif /* OPENSSL */ /* Keys Command */ - if (my_config.auth.keys) + if (my_config.auth.keys) { getauthkeys(my_config.auth.keys); + free(my_config.auth.keys); + my_config.auth.keys = NULL; + } /* Control Key Command */ if (my_config.auth.control_key != 0) diff --git a/ports/winnt/ntpd/ntservice.c b/ports/winnt/ntpd/ntservice.c index 34b8693a41..682526cd41 100644 --- a/ports/winnt/ntpd/ntservice.c +++ b/ports/winnt/ntpd/ntservice.c @@ -17,7 +17,10 @@ /* $Id: ntservice.c,v 1.3.2.1.10.3 2004/03/08 04:04:22 marka Exp $ */ -#include +#ifdef HAVE_CONFIG_H +# include +#endif + #include #include @@ -148,17 +151,27 @@ ntservice_init() { SetConsoleTitle(ConsoleTitle); } - #if defined(_MSC_VER) && defined(_DEBUG) +#ifdef _CRTDBG_MAP_ALLOC /* ask the runtime to dump memory leaks at exit */ - _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - #ifdef WANT_LEAK_CHECK_ON_STDERR_TOO - /* hart: I haven't seen this work, running ntpd.exe -n from a shell */ - /* to both a file and the debugger output window */ - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); - /* the file being stderr */ + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF + | _CRTDBG_LEAK_CHECK_DF /* report on leaks at exit */ + | _CRTDBG_CHECK_ALWAYS_DF /* Check heap every alloc/dealloc */ +#ifdef MALLOC_LINT + | _CRTDBG_DELAY_FREE_MEM_DF /* Don't actually free memory */ +#endif + ); +#ifdef DOES_NOT_WORK + /* + * hart: I haven't seen this work, running ntpd.exe -n from a shell + * to both a file and the debugger output window. Docs indicate it + * should cause leak report to go to stderr, but it's only seen if + * ntpd runs under a debugger (in the debugger's output), even with + * this block of code enabled. + */ _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); - #endif - #endif /* _MSC_VER && _DEBUG */ + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); +#endif +#endif /* using MS debug C runtime heap, _CRTDBG_MAP_ALLOC */ atexit( ntservice_exit ); }