diff options
author | David Disseldorp <ddiss@samba.org> | 2014-02-20 19:47:44 +0100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2014-02-21 12:02:43 +1300 |
commit | 385f0c9ea05a0f37388cf549102fc13ef9e6691a (patch) | |
tree | 83b1e7d8aa5a084a13ac0a8dbf5aad0d4dc58be7 /source3/client | |
parent | 72696c3f5a01da5ba07ee3495bd01c8288cb1b6d (diff) | |
download | samba-385f0c9ea05a0f37388cf549102fc13ef9e6691a.tar.gz |
clitar: check for path_base_name() allocation errors
Add a separate NTSTATUS return code, as base string may be NULL on
successful return.
Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source3/client')
-rw-r--r-- | source3/client/clitar.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c index ab41cd0312c..c8f8fec3860 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -222,7 +222,7 @@ static NTSTATUS get_file_callback(struct cli_state *cli, /* utilities */ static char *fix_unix_path(char *path, bool removeprefix); -static char *path_base_name(const char *path); +static NTSTATUS path_base_name(TALLOC_CTX *ctx, const char *path, char **_base); static const char* skip_useless_char_in_path(const char *p); static int make_remote_path(const char *full_path); static int max_token (const char *str); @@ -799,14 +799,20 @@ static int tar_create_from_list(struct tar *t) TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); int err = 0; NTSTATUS status; - const char *path, *mask, *base, *start_dir; + char *base; + const char *path, *mask, *start_dir; int i; start_dir = talloc_strdup(ctx, client_get_cur_dir()); for (i = 0; i < t->path_list_size; i++) { path = t->path_list[i]; - base = path_base_name(path); + base = NULL; + status = path_base_name(ctx, path, &base); + if (!NT_STATUS_IS_OK(status)) { + err = 1; + goto out; + } mask = PANIC_IF_NULL(talloc_asprintf(ctx, "%s\\%s", client_get_cur_dir(), path)); @@ -815,7 +821,11 @@ static int tar_create_from_list(struct tar *t) if (base != NULL) { base = talloc_asprintf(ctx, "%s%s\\", - client_get_cur_dir(), path_base_name(path)); + client_get_cur_dir(), base); + if (base == NULL) { + err = 1; + goto out; + } DBG(5, ("cd '%s' before do_list\n", base)); client_set_cur_dir(base); } @@ -1721,9 +1731,8 @@ static char *fix_unix_path(char *path, bool do_remove_prefix) * * If @path doesn't contain any directory separator return NULL. */ -static char *path_base_name(const char *path) +static NTSTATUS path_base_name(TALLOC_CTX *ctx, const char *path, char **_base) { - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_tos()); char *base = NULL; int last = -1; int i; @@ -1735,11 +1744,16 @@ static char *path_base_name(const char *path) } if (last >= 0) { - base = PANIC_IF_NULL(talloc_strdup(ctx, path)); + base = talloc_strdup(ctx, path); + if (base == NULL) { + return NT_STATUS_NO_MEMORY; + } + base[last] = 0; } - return base; + *_base = base; + return NT_STATUS_OK; } #else |