]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1211] keysdir free()d twice #ifdef DEBUG
authorDave Hart <hart@ntp.org>
Wed, 3 Jun 2009 01:35:02 +0000 (01:35 +0000)
committerDave Hart <hart@ntp.org>
Wed, 3 Jun 2009 01:35:02 +0000 (01:35 +0000)
bk: 4a25d346bEbjMl-AfvuLkEVN5eaRmA

ChangeLog
libntp/decodenetnum.c
ntpd/ntp_config.c
ports/winnt/ntpd/ntservice.c

index b922dc50383ce7afb0c3e11dea12939f0d5c6f7f..f71fba2b41939d454b1dab8361c5cafcd5f5b8ae 100644 (file)
--- 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 <stenn@ntp.org>
 * [Bug 1200] Enable IPv6 in Windows port
 * Lose FLAG_FIXPOLL, from Dave Mills.
index 5d646c377ad247414e12b0dc139cbb2a3dbd2aad..f5db29ab420a83db43d10848f25293ec46042040 100644 (file)
@@ -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); 
index 5be1e3af5a7d30805fbb2e9e3cf4c21fa25ac2bf..00d4f98e232718edf8cbc65b1b1770483b2cdabe 100644 (file)
@@ -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)
index 34b8693a41d83cd44d82bde82d4537eba4c804a9..682526cd41480745076ab42280de06936cbf7abd 100644 (file)
 
 /* $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>
@@ -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 );
 }