diff options
-rw-r--r-- | source4/torture/masktest.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/source4/torture/masktest.c b/source4/torture/masktest.c index 5eccf86f11..6e9ae89336 100644 --- a/source4/torture/masktest.c +++ b/source4/torture/masktest.c @@ -74,6 +74,7 @@ return a connection to a server *******************************************************/ static struct smbcli_state *connect_one(struct resolve_context *resolve_ctx, struct event_context *ev, + TALLOC_CTX *mem_ctx, char *share, const char **ports, struct smbcli_options *options, struct smbcli_session_options *session_options) @@ -82,12 +83,9 @@ static struct smbcli_state *connect_one(struct resolve_context *resolve_ctx, char *server; NTSTATUS status; - server = smb_xstrdup(share+2); + server = talloc_strdup(mem_ctx, share+2); share = strchr_m(server,'\\'); - if (!share) { - SAFE_FREE(server); - return NULL; - } + if (!share) return NULL; *share = 0; share++; @@ -100,8 +98,6 @@ static struct smbcli_state *connect_one(struct resolve_context *resolve_ctx, cmdline_credentials, resolve_ctx, ev, options, session_options); - SAFE_FREE(server); - if (!NT_STATUS_IS_OK(status)) { return NULL; } @@ -170,7 +166,7 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask, char *file) { int fnum; - char *res1; + char res1[256]; char *res2; static int count; char *short_name = NULL; @@ -179,7 +175,7 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask, count++; - res1 = talloc_strdup(mem_ctx, "---"); + safe_strcpy(res1, "---", sizeof(res1)); state.mem_ctx = mem_ctx; @@ -191,8 +187,9 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask, smbcli_close(cli->tree, fnum); resultp = res1; + short_name = talloc_strdup(mem_ctx, ""); get_real_name(mem_ctx, cli, &long_name, &short_name); - res1 = talloc_strdup(mem_ctx, "---"); + safe_strcpy(res1, "---", sizeof(res1)); smbcli_list_new(cli->tree, mask, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY, RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, @@ -214,16 +211,14 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask, } static void test_mask(int argc, char *argv[], + TALLOC_CTX *mem_ctx, struct smbcli_state *cli) { - TALLOC_CTX *mem_ctx; char *mask, *file; int l1, l2, i, l; int mc_len = strlen(maskchars); int fc_len = strlen(filechars); - mem_ctx = talloc_init("test_mask"); - smbcli_mkdir(cli->tree, "\\masktest"); smbcli_unlink(cli->tree, "\\masktest\\*"); @@ -304,6 +299,7 @@ static void usage(poptContext pc) poptContext pc; int argc_new, i; char **argv_new; + TALLOC_CTX *mem_ctx; enum {OPT_UNCLIST=1000}; struct poptOption long_options[] = { POPT_AUTOHELP @@ -360,14 +356,16 @@ static void usage(poptContext pc) lp_ctx = cmdline_lp_ctx; - ev = s4_event_context_init(talloc_autofree_context()); + mem_ctx = talloc_autofree_context(); + + ev = s4_event_context_init(mem_ctx); gensec_init(lp_ctx); lp_smbcli_options(lp_ctx, &options); lp_smbcli_session_options(lp_ctx, &session_options); - cli = connect_one(lp_resolve_context(lp_ctx), ev, share, + cli = connect_one(lp_resolve_context(lp_ctx), ev, mem_ctx, share, lp_smb_ports(lp_ctx), &options, &session_options); if (!cli) { DEBUG(0,("Failed to connect to %s\n", share)); @@ -378,7 +376,7 @@ static void usage(poptContext pc) DEBUG(0,("seed=%d format --- --- (server, correct)\n", seed)); srandom(seed); - test_mask(argc_new-1, argv_new+1, cli); + test_mask(argc_new-1, argv_new+1, mem_ctx, cli); return(0); } |