s3-winexe: Fix winexe core dump (use-after-free)
authorGünther Deschner <gd@samba.org>
Thu, 4 Nov 2021 21:22:44 +0000 (22:22 +0100)
committerGünther Deschner <gd@samba.org>
Fri, 5 Nov 2021 11:43:57 +0000 (11:43 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14893

Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Günther Deschner <gd@samba.org>
Autobuild-Date(master): Fri Nov  5 11:43:57 UTC 2021 on sn-devel-184

examples/winexe/winexe.c

index 3e0813a40913d08c9c7d7d3f81c530c3bedd79e0..59fb9dbdebb8564238991031a0a27f86834dd5e8 100644 (file)
@@ -220,8 +220,6 @@ static void parse_args(int argc, const char *argv[],
                *port_str = '\0';
        }
 
-       poptFreeContext(pc);
-
        if (options->runas == NULL && options->runas_file != NULL) {
                struct cli_credentials *runas_cred;
                const char *user;
@@ -253,9 +251,19 @@ static void parse_args(int argc, const char *argv[],
 
        options->credentials = samba_cmdline_get_creds();
 
-       options->hostname = argv_new[0] + 2;
+       options->hostname = talloc_strdup(mem_ctx, argv_new[0] + 2);
+       if (options->hostname == NULL) {
+               DBG_ERR("Out of memory\n");
+               exit(1);
+       }
        options->port = port;
-       options->cmd = argv_new[1];
+       options->cmd = talloc_strdup(mem_ctx, argv_new[1]);
+       if (options->cmd == NULL) {
+               DBG_ERR("Out of memory\n");
+               exit(1);
+       }
+
+       poptFreeContext(pc);
 
        options->flags = flag_interactive;
        if (flag_reinstall) {