diff options
Diffstat (limited to 'libarchive/archive_read_disk_windows.c')
-rw-r--r-- | libarchive/archive_read_disk_windows.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/libarchive/archive_read_disk_windows.c b/libarchive/archive_read_disk_windows.c index a774305d0cf2..689a45958c15 100644 --- a/libarchive/archive_read_disk_windows.c +++ b/libarchive/archive_read_disk_windows.c @@ -1652,7 +1652,7 @@ tree_push(struct tree *t, const wchar_t *path, const wchar_t *full_path, /* * Append a name to the current dir path. */ -static void +static int tree_append(struct tree *t, const wchar_t *name, size_t name_length) { size_t size_needed; @@ -1665,7 +1665,8 @@ tree_append(struct tree *t, const wchar_t *name, size_t name_length) /* Resize pathname buffer as needed. */ size_needed = name_length + t->dirname_length + 2; - archive_wstring_ensure(&t->path, size_needed); + if (archive_wstring_ensure(&t->path, size_needed) == NULL) + return (TREE_ERROR_FATAL); /* Add a separating '/' if it's needed. */ if (t->dirname_length > 0 && t->path.s[archive_strlen(&t->path)-1] != L'/') @@ -1677,13 +1678,15 @@ tree_append(struct tree *t, const wchar_t *name, size_t name_length) t->full_path.s[t->full_path_dir_length] = L'\0'; t->full_path.length = t->full_path_dir_length; size_needed = name_length + t->full_path_dir_length + 2; - archive_wstring_ensure(&t->full_path, size_needed); + if (archive_wstring_ensure(&t->full_path, size_needed) == NULL) + return (TREE_ERROR_FATAL); /* Add a separating '\' if it's needed. */ if (t->full_path.s[archive_strlen(&t->full_path)-1] != L'\\') archive_wstrappend_wchar(&t->full_path, L'\\'); archive_wstrncat(&t->full_path, name, name_length); t->restore_time.full_path = t->full_path.s; } + return (0); } /* @@ -1697,7 +1700,10 @@ tree_open(const wchar_t *path, int symlink_mode, int restore_time) t = calloc(1, sizeof(*t)); archive_string_init(&(t->full_path)); archive_string_init(&t->path); - archive_wstring_ensure(&t->path, 15); + if (archive_wstring_ensure(&t->path, 15) == NULL) { + free(t); + return (NULL); + } t->initial_symlink_mode = symlink_mode; return (tree_reopen(t, path, restore_time)); } @@ -1756,7 +1762,8 @@ tree_reopen(struct tree *t, const wchar_t *path, int restore_time) p = wcsrchr(base, L'/'); if (p != NULL) { *p = L'\0'; - tree_append(t, base, p - base); + if (tree_append(t, base, p - base)) + goto failed; t->dirname_length = archive_strlen(&t->path); base = p + 1; } @@ -1892,8 +1899,10 @@ tree_next(struct tree *t) } /* Top stack item needs a regular visit. */ t->current = t->stack; - tree_append(t, t->stack->name.s, + r = tree_append(t, t->stack->name.s, archive_strlen(&(t->stack->name))); + if (r != 0) + return (r); //t->dirname_length = t->path_length; //tree_pop(t); t->stack->flags &= ~needsFirstVisit; @@ -1901,8 +1910,10 @@ tree_next(struct tree *t) } else if (t->stack->flags & needsDescent) { /* Top stack item is dir to descend into. */ t->current = t->stack; - tree_append(t, t->stack->name.s, + r = tree_append(t, t->stack->name.s, archive_strlen(&(t->stack->name))); + if (r != 0) + return (r); t->stack->flags &= ~needsDescent; r = tree_descent(t); if (r != 0) { @@ -1945,9 +1956,10 @@ tree_dir_next_windows(struct tree *t, const wchar_t *pattern) struct archive_wstring pt; archive_string_init(&pt); - archive_wstring_ensure(&pt, + if (archive_wstring_ensure(&pt, archive_strlen(&(t->full_path)) - + 2 + wcslen(pattern)); + + 2 + wcslen(pattern)) == NULL) + return (TREE_ERROR_FATAL); archive_wstring_copy(&pt, &(t->full_path)); archive_wstrappend_wchar(&pt, L'\\'); archive_wstrcat(&pt, pattern); @@ -1979,7 +1991,9 @@ tree_dir_next_windows(struct tree *t, const wchar_t *pattern) continue; if (name[0] == L'.' && name[1] == L'.' && name[2] == L'\0') continue; - tree_append(t, name, namelen); + r = tree_append(t, name, namelen); + if (r != 0) + return (r); return (t->visit_type = TREE_REGULAR); } } |