The branch, master has been updated via 913b2a1 clitar: don't panic, propagate talloc errors upwards via 83a653f clitar: propagate make_remote_path() talloc errors via 55de6d6 clitar: return allocation errors from is_subpath() via 8522597 clitar: add error return to tar_path_in_list() via 6d5b56d clitar: add error return to tar_extract_skip_path() via 4d9e1b6 clitar: add error return to tar_create_skip_path() via 385f0c9 clitar: check for path_base_name() allocation errors from 72696c3 lib: Fix a typo
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 913b2a172d74b60bb5a7396eb09ad4af4b748021 Author: David Disseldorp <dd...@samba.org> Date: Thu Feb 20 19:47:50 2014 +0100 clitar: don't panic, propagate talloc errors upwards Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> Autobuild-User(master): Andrew Bartlett <abart...@samba.org> Autobuild-Date(master): Fri Feb 21 02:49:36 CET 2014 on sn-devel-104 commit 83a653fadbdb3167ac53b51b2694d2fd6baf962b Author: David Disseldorp <dd...@samba.org> Date: Thu Feb 20 19:47:49 2014 +0100 clitar: propagate make_remote_path() talloc errors Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 55de6d60ef72b105883117b36963a7a145268223 Author: David Disseldorp <dd...@samba.org> Date: Thu Feb 20 19:47:48 2014 +0100 clitar: return allocation errors from is_subpath() Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 852259773b4a2ab63ed6df2b41fa73eb22ba81c4 Author: David Disseldorp <dd...@samba.org> Date: Thu Feb 20 19:47:47 2014 +0100 clitar: add error return to tar_path_in_list() In preparation for propagation of memory allocation errors from is_subpath(). Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 6d5b56dc7ab8b957af58c584d91ac4864156ced2 Author: David Disseldorp <dd...@samba.org> Date: Thu Feb 20 19:47:46 2014 +0100 clitar: add error return to tar_extract_skip_path() Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 4d9e1b68b7b636a435f55c25df9ab8f51922b36e Author: David Disseldorp <dd...@samba.org> Date: Thu Feb 20 19:47:45 2014 +0100 clitar: add error return to tar_create_skip_path() In preparation for propagation of memory allocation errors from tar_path_in_list() and friends. Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 385f0c9ea05a0f37388cf549102fc13ef9e6691a Author: David Disseldorp <dd...@samba.org> Date: Thu Feb 20 19:47:44 2014 +0100 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 <dd...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> ----------------------------------------------------------------------- Summary of changes: source3/client/clitar.c | 416 +++++++++++++++++++++++++++++++++-------------- 1 files changed, 295 insertions(+), 121 deletions(-) Changeset truncated at 500 lines: diff --git a/source3/client/clitar.c b/source3/client/clitar.c index ab41cd0..e4d391a 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -80,24 +80,10 @@ /* prepend module name and line number to debug messages */ #define DBG(a, b) (DEBUG(a, ("tar:%-4d ", __LINE__)), DEBUG(a, b)) -/* preprocessor magic to strigify __LINE__ (int) */ +/* preprocessor magic to stringify __LINE__ (int) */ #define STR1(x) #x #define STR2(x) STR1(x) -/* helper macro to die in case of NULL pointer */ -#define PANIC_IF_NULL(x) \ - _panic_if_null(x, __FILE__ ":" STR2(__LINE__) " (" #x ") == NULL\n") - -/* prototype to silent gcc warning */ -static inline void* _panic_if_null(void *p, const char *expr); -static inline void* _panic_if_null(void *p, const char *expr) -{ - if (p == NULL) { - smb_panic(expr); - } - return p; -} - /** * Number of byte in a block unit. */ @@ -199,18 +185,20 @@ static int tar_read_inclusion_file(struct tar *t, const char* filename); static int tar_send_file(struct tar *t, struct archive_entry *entry); static int tar_set_blocksize(struct tar *t, int size); static int tar_set_newer_than(struct tar *t, const char *filename); -static void tar_add_selection_path(struct tar *t, const char *path); +static NTSTATUS tar_add_selection_path(struct tar *t, const char *path); static void tar_dump(struct tar *t); -static bool tar_extract_skip_path(struct tar *t, struct archive_entry *entry); +static NTSTATUS tar_extract_skip_path(struct tar *t, + struct archive_entry *entry, + bool *_skip); static TALLOC_CTX *tar_reset_mem_context(struct tar *t); static void tar_free_mem_context(struct tar *t); -static bool tar_create_skip_path(struct tar *t, - const char *fullpath, - const struct file_info *finfo); +static NTSTATUS tar_create_skip_path(struct tar *t, + const char *fullpath, + const struct file_info *finfo, + bool *_skip); -static bool tar_path_in_list(struct tar *t, - const char *path, - bool reverse); +static NTSTATUS tar_path_in_list(struct tar *t, const char *path, + bool reverse, bool *_is_in_list); static int tar_get_file(struct tar *t, const char *full_dos_path, @@ -222,11 +210,12 @@ 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); -static bool is_subpath(const char *sub, const char *full); +static NTSTATUS is_subpath(const char *sub, const char *full, + bool *_subpath_match); static int set_remote_attr(const char *filename, uint16 new_attr, int mode); /** @@ -248,9 +237,12 @@ int cmd_block(void) /* XXX: from client.c */ const extern char *cmd_ptr; char *buf; - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); int err = 0; bool ok; + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL); if (!ok) { @@ -284,7 +276,7 @@ int cmd_tarmode(void) const extern char *cmd_ptr; char *buf; int i; - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); + TALLOC_CTX *ctx; struct { const char *cmd; @@ -305,6 +297,11 @@ int cmd_tarmode(void) {"noverbose", &tar_ctx.mode.verbose, false}, }; + ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } + while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { for (i = 0; i < ARRAY_SIZE(table); i++) { if (strequal(table[i].cmd, buf)) { @@ -335,7 +332,6 @@ int cmd_tarmode(void) */ int cmd_tar(void) { - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); const extern char *cmd_ptr; const char *flag; const char **val; @@ -345,6 +341,10 @@ int cmd_tar(void) int err = 0; bool ok; int rc; + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL); if (!ok) { @@ -354,7 +354,11 @@ int cmd_tar(void) } flag = buf; - val = PANIC_IF_NULL(talloc_array(ctx, const char*, maxtok)); + val = talloc_array(ctx, const char *, maxtok); + if (val == NULL) { + err = 1; + goto out; + } while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { val[i++] = buf; @@ -392,10 +396,12 @@ int cmd_setmode(void) char *fname = NULL; uint16 attr[2] = {0}; int mode = ATTR_SET; - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); int err = 0; bool ok; - + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL); if (!ok) { @@ -404,10 +410,10 @@ int cmd_setmode(void) goto out; } - fname = PANIC_IF_NULL(talloc_asprintf(ctx, + fname = talloc_asprintf(ctx, "%s%s", client_get_cur_dir(), - buf)); + buf); if (fname == NULL) { err = 1; goto out; @@ -503,6 +509,9 @@ int tar_parse_args(struct tar* t, } ctx = tar_reset_mem_context(t); + if (ctx == NULL) { + return 1; + } /* * Reset back some options - could be from interactive version * all other modes are left as they are @@ -635,7 +644,10 @@ int tar_parse_args(struct tar* t, } /* handle TARFILE */ - t->tar_path = PANIC_IF_NULL(talloc_strdup(ctx, val[ival])); + t->tar_path = talloc_strdup(ctx, val[ival]); + if (t->tar_path == NULL) { + return 1; + } ival++; /* @@ -664,7 +676,11 @@ int tar_parse_args(struct tar* t, } else { int i; for (i = ival; i < valsize; i++) { - tar_add_selection_path(t, val[i]); + NTSTATUS status; + status = tar_add_selection_path(t, val[i]); + if (!NT_STATUS_IS_OK(status)) { + return 1; + } } } @@ -710,11 +726,14 @@ int tar_process(struct tar *t) */ static int tar_create(struct tar* t) { - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); int r; int err = 0; NTSTATUS status; const char *mask; + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } t->archive = archive_write_new(); @@ -763,8 +782,11 @@ static int tar_create(struct tar* t) goto out_close; } } else { - mask = PANIC_IF_NULL(talloc_asprintf(ctx, "%s\\*", - client_get_cur_dir())); + mask = talloc_asprintf(ctx, "%s\\*", client_get_cur_dir()); + if (mask == NULL) { + err = 1; + goto out_close; + } DBG(5, ("tar_process do_list with mask: %s\n", mask)); status = do_list(mask, TAR_DO_LIST_ATTR, get_file_callback, false, true); if (!NT_STATUS_IS_OK(status)) { @@ -796,26 +818,47 @@ out: */ 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; + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } start_dir = talloc_strdup(ctx, client_get_cur_dir()); + if (start_dir == NULL) { + err = 1; + goto out; + } for (i = 0; i < t->path_list_size; i++) { path = t->path_list[i]; - base = path_base_name(path); - mask = PANIC_IF_NULL(talloc_asprintf(ctx, "%s\\%s", - client_get_cur_dir(), path)); + base = NULL; + status = path_base_name(ctx, path, &base); + if (!NT_STATUS_IS_OK(status)) { + err = 1; + goto out; + } + mask = talloc_asprintf(ctx, "%s\\%s", + client_get_cur_dir(), path); + if (mask == NULL) { + err = 1; + goto out; + } DBG(5, ("incl. path='%s', base='%s', mask='%s'\n", path, base ? base : "NULL", mask)); 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); } @@ -846,22 +889,34 @@ static NTSTATUS get_file_callback(struct cli_state *cli, struct file_info *finfo, const char *dir) { - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); - NTSTATUS err = NT_STATUS_OK; + NTSTATUS status = NT_STATUS_OK; char *remote_name; const char *initial_dir = client_get_cur_dir(); + bool skip = false; int rc; + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return NT_STATUS_NO_MEMORY; + } - remote_name = PANIC_IF_NULL(talloc_asprintf(ctx, "%s%s", - initial_dir, finfo->name)); + remote_name = talloc_asprintf(ctx, "%s%s", initial_dir, finfo->name); + if (remote_name == NULL) { + status = NT_STATUS_NO_MEMORY; + goto out; + } if (strequal(finfo->name, "..") || strequal(finfo->name, ".")) { goto out; } - rc = tar_create_skip_path(&tar_ctx, remote_name, finfo); - if (rc != 0) { + status = tar_create_skip_path(&tar_ctx, remote_name, finfo, &skip); + if (!NT_STATUS_IS_OK(status)) { + goto out; + } + + if (skip) { DBG(5, ("--- %s\n", remote_name)); + status = NT_STATUS_OK; goto out; } @@ -870,14 +925,22 @@ static NTSTATUS get_file_callback(struct cli_state *cli, char *new_dir; char *mask; - old_dir = PANIC_IF_NULL(talloc_strdup(ctx, initial_dir)); - new_dir = PANIC_IF_NULL(talloc_asprintf(ctx, "%s%s\\", - initial_dir, finfo->name)); - mask = PANIC_IF_NULL(talloc_asprintf(ctx, "%s*", new_dir)); + old_dir = talloc_strdup(ctx, initial_dir); + new_dir = talloc_asprintf(ctx, "%s%s\\", + initial_dir, finfo->name); + if ((old_dir == NULL) || (new_dir == NULL)) { + status = NT_STATUS_NO_MEMORY; + goto out; + } + mask = talloc_asprintf(ctx, "%s*", new_dir); + if (mask == NULL) { + status = NT_STATUS_NO_MEMORY; + goto out; + } rc = tar_get_file(&tar_ctx, remote_name, finfo); if (rc != 0) { - err = NT_STATUS_UNSUCCESSFUL; + status = NT_STATUS_UNSUCCESSFUL; goto out; } @@ -887,14 +950,14 @@ static NTSTATUS get_file_callback(struct cli_state *cli, } else { rc = tar_get_file(&tar_ctx, remote_name, finfo); if (rc != 0) { - err = NT_STATUS_UNSUCCESSFUL; + status = NT_STATUS_UNSUCCESSFUL; goto out; } } out: talloc_free(ctx); - return err; + return status; } /** @@ -907,7 +970,6 @@ static int tar_get_file(struct tar *t, struct file_info *finfo) { extern struct cli_state *cli; - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); NTSTATUS status; struct archive_entry *entry; char *full_unix_path; @@ -917,6 +979,10 @@ static int tar_get_file(struct tar *t, uint16_t remote_fd = (uint16_t)-1; int err = 0, r; const bool isdir = finfo->mode & FILE_ATTRIBUTE_DIRECTORY; + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } DBG(5, ("+++ %s\n", full_dos_path)); @@ -931,7 +997,11 @@ static int tar_get_file(struct tar *t, set_remote_attr(full_dos_path, FILE_ATTRIBUTE_ARCHIVE, ATTR_UNSET); } - full_unix_path = PANIC_IF_NULL(talloc_asprintf(ctx, ".%s", full_dos_path)); + full_unix_path = talloc_asprintf(ctx, ".%s", full_dos_path); + if (full_unix_path == NULL) { + err = 1; + goto out; + } string_replace(full_unix_path, '\\', '/'); entry = archive_entry_new(); archive_entry_copy_pathname(entry, full_unix_path); @@ -1036,6 +1106,8 @@ static int tar_extract(struct tar *t) } for (;;) { + NTSTATUS status; + bool skip; r = archive_read_next_header(t->archive, &entry); if (r == ARCHIVE_EOF) { break; @@ -1049,8 +1121,12 @@ static int tar_extract(struct tar *t) goto out; } - rc = tar_extract_skip_path(t, entry); - if (rc != 0) { + status = tar_extract_skip_path(t, entry, &skip); + if (!NT_STATUS_IS_OK(status)) { + err = 1; + goto out; + } + if (skip) { DBG(5, ("--- %s\n", archive_entry_pathname(entry))); continue; } @@ -1084,7 +1160,6 @@ out: static int tar_send_file(struct tar *t, struct archive_entry *entry) { extern struct cli_state *cli; - TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); char *dos_path; char *full_path; NTSTATUS status; @@ -1093,12 +1168,28 @@ static int tar_send_file(struct tar *t, struct archive_entry *entry) int flags = O_RDWR | O_CREAT | O_TRUNC; mode_t mode = archive_entry_filetype(entry); int rc; + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } - dos_path = PANIC_IF_NULL(talloc_strdup(ctx, archive_entry_pathname(entry))); + dos_path = talloc_strdup(ctx, archive_entry_pathname(entry)); + if (dos_path == NULL) { + err = 1; + goto out; + } fix_unix_path(dos_path, true); - full_path = PANIC_IF_NULL(talloc_strdup(ctx, client_get_cur_dir())); - full_path = PANIC_IF_NULL(talloc_strdup_append(full_path, dos_path)); + full_path = talloc_strdup(ctx, client_get_cur_dir()); + if (full_path == NULL) { + err = 1; + goto out; + } + full_path = talloc_strdup_append(full_path, dos_path); + if (full_path == NULL) { + err = 1; + goto out; + } if (mode != AE_IFREG && mode != AE_IFDIR) { DBG(0, ("Skipping non-dir & non-regular file %s\n", full_path)); @@ -1168,19 +1259,28 @@ out: * tar_add_selection_path - add a path to the path list * @path: path to add */ -static void tar_add_selection_path(struct tar *t, const char *path) +static NTSTATUS tar_add_selection_path(struct tar *t, const char *path) { + const char **list; TALLOC_CTX *ctx = t->talloc_ctx; if (!t->path_list) { - t->path_list = PANIC_IF_NULL(str_list_make_empty(ctx)); + t->path_list = str_list_make_empty(ctx); + if (t->path_list == NULL) { + return NT_STATUS_NO_MEMORY; + } t->path_list_size = 0; } - /* cast to silent gcc const-qual warning */ - t->path_list = PANIC_IF_NULL(str_list_add((void*)t->path_list, - path)); + /* cast to silence gcc const-qual warning */ + list = str_list_add((void *)t->path_list, path); + if (list == NULL) { + return NT_STATUS_NO_MEMORY; + } + t->path_list = discard_const_p(char *, list); t->path_list_size++; fix_unix_path(t->path_list[t->path_list_size - 1], true); + -- Samba Shared Repository