]> granicus.if.org Git - sudo/commitdiff
Plug memory leak when a particular Path is set more than once.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Nov 2016 20:57:50 +0000 (13:57 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Nov 2016 20:57:50 +0000 (13:57 -0700)
lib/util/regress/sudo_conf/test1.in
lib/util/sudo_conf.c

index d572cad992be0d10f77eb63a6b364c254172798d..41282d7daf219ec563ef27de112aecca6bab6f64 100644 (file)
@@ -42,6 +42,7 @@ Path askpass /usr/X11R6/bin/ssh-askpass
 # The compiled-in value is usually sufficient and should only be changed
 # if you rename or move the sudo_noexec.so file.
 #
+Path noexec /usr/local/libexec/sudo_noexec.so
 Path noexec /usr/libexec/sudo_noexec.so
 
 #
index f5dd57a9dd33a2c3e9e3e885a2af92104d97a98f..0b88badacde48742bb534f7bab65752598359d7e 100644 (file)
@@ -64,6 +64,7 @@ struct sudo_conf_table {
 struct sudo_conf_path_table {
     const char *pname;
     unsigned int pnamelen;
+    bool dynamic;
     char *pval;
 };
 
@@ -115,10 +116,10 @@ static struct sudo_conf_data {
     TAILQ_HEAD_INITIALIZER(sudo_conf_data.debugging),
     TAILQ_HEAD_INITIALIZER(sudo_conf_data.plugins),
     {
-       { "askpass", sizeof("askpass") - 1, _PATH_SUDO_ASKPASS },
-       { "sesh", sizeof("sesh") - 1, _PATH_SUDO_SESH },
-       { "noexec", sizeof("noexec") - 1, _PATH_SUDO_NOEXEC },
-       { "plugin_dir", sizeof("plugin_dir") - 1, _PATH_SUDO_PLUGIN_DIR },
+       { "askpass", sizeof("askpass") - 1, false, _PATH_SUDO_ASKPASS },
+       { "sesh", sizeof("sesh") - 1, false, _PATH_SUDO_SESH },
+       { "noexec", sizeof("noexec") - 1, false, _PATH_SUDO_NOEXEC },
+       { "plugin_dir", sizeof("plugin_dir") - 1, false, _PATH_SUDO_PLUGIN_DIR },
        { NULL }
     }
 };
@@ -185,8 +186,10 @@ parse_path(const char *entry, const char *conf_file, unsigned int lineno)
                    debug_return_int(-1);
                }
            }
-           /* XXX - potential memory leak */
+           if (cur->dynamic)
+               free(cur->pval);
            cur->pval = pval;
+           cur->dynamic = true;
            sudo_debug_printf(SUDO_DEBUG_INFO, "%s: %s:%u: Path %s %s",
                __func__, conf_file, lineno, cur->pname,
                pval ? pval : "(none)");
@@ -633,6 +636,10 @@ sudo_conf_clear_paths_v1(void)
     struct sudo_conf_path_table *cur;
     debug_decl(sudo_conf_clear_paths, SUDO_DEBUG_UTIL)
 
-    for (cur = sudo_conf_data.path_table; cur->pname != NULL; cur++)
+    for (cur = sudo_conf_data.path_table; cur->pname != NULL; cur++) {
+       if (cur->dynamic)
+           free(cur->pval);
        cur->pval = NULL;
+       cur->dynamic = false;
+    }
 }