* [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 <stenn@ntp.org>
* [Bug 1200] Enable IPv6 in Windows port
* Lose FLAG_FIXPOLL, from Dave Mills.
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);
#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;
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);
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)
{
DESTROY_QUEUE(my_config.ttl);
DESTROY_QUEUE(my_config.trap);
DESTROY_QUEUE(my_config.vars);
-
- free_auth_node();
}
#endif /* DEBUG */
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 */
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
#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)
/* $Id: ntservice.c,v 1.3.2.1.10.3 2004/03/08 04:04:22 marka Exp $ */
-#include <config.h>
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <stdio.h>
#include <ntp_cmdargs.h>
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 );
}