From: Michihiro NAKAJIMA Date: Mon, 23 Jan 2012 09:55:01 +0000 (-0500) Subject: Eliminate invoking __archive_errx() from archive_acl.c. X-Git-Tag: v3.0.4~2^2~158 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c729cd8742faf4b9cfc0fd2b7dc3acc32aef7cf;p=thirdparty%2Flibarchive.git Eliminate invoking __archive_errx() from archive_acl.c. SVN-Revision: 4195 --- diff --git a/libarchive/archive_acl.c b/libarchive/archive_acl.c index 6fccd25ff..e4ce90d0e 100644 --- a/libarchive/archive_acl.c +++ b/libarchive/archive_acl.c @@ -421,7 +421,7 @@ archive_acl_next(struct archive *a, struct archive_acl *acl, int want_type, int *id = acl->acl_p->id; if (archive_mstring_get_mbs(a, &acl->acl_p->name, name) != 0) { if (errno == ENOMEM) - __archive_errx(1, "No memory"); + return (ARCHIVE_FATAL); *name = NULL; } acl->acl_p = acl->acl_p->next; @@ -465,8 +465,7 @@ archive_acl_text_w(struct archive *a, struct archive_acl *acl, int flags) if (r == 0 && wname != NULL) length += wcslen(wname); else if (r < 0 && errno == ENOMEM) - __archive_errx(1, "No memory to generate " - "the text version of the ACL"); + return (NULL); else length += sizeof(uid_t) * 3 + 1; length ++; /* colon */ @@ -490,7 +489,7 @@ archive_acl_text_w(struct archive *a, struct archive_acl *acl, int flags) /* Now, allocate the string and actually populate it. */ wp = acl->acl_text_w = (wchar_t *)malloc(length * sizeof(wchar_t)); if (wp == NULL) - __archive_errx(1, "No memory to generate the text version of the ACL"); + return (NULL); count = 0; if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_USER_OBJ, NULL, @@ -518,8 +517,7 @@ archive_acl_text_w(struct archive *a, struct archive_acl *acl, int flags) ap->permset, id); count++; } else if (r < 0 && errno == ENOMEM) - __archive_errx(1, "No memory to generate " - "the text version of the ACL"); + return (NULL); ap = ap->next; } } @@ -546,8 +544,7 @@ archive_acl_text_w(struct archive *a, struct archive_acl *acl, int flags) wname, ap->permset, id); count ++; } else if (r < 0 && errno == ENOMEM) - __archive_errx(1, "No memory to generate " - "the text version of the ACL"); + return (NULL); ap = ap->next; } } @@ -685,7 +682,7 @@ archive_acl_text_l(struct archive_acl *acl, int flags, /* Now, allocate the string and actually populate it. */ p = acl->acl_text = (char *)malloc(length); if (p == NULL) - __archive_errx(1, "No memory to generate the text version of the ACL"); + return (-1); count = 0; if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { append_entry(&p, NULL, ARCHIVE_ENTRY_ACL_USER_OBJ, NULL, diff --git a/libarchive/archive_entry.c b/libarchive/archive_entry.c index 4153dcd84..b531c77d2 100644 --- a/libarchive/archive_entry.c +++ b/libarchive/archive_entry.c @@ -1318,7 +1318,12 @@ int archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type, int *permset, int *tag, int *id, const char **name) { - return archive_acl_next(entry->archive, &entry->acl, want_type, type, permset, tag, id, name); + int r; + r = archive_acl_next(entry->archive, &entry->acl, want_type, type, + permset, tag, id, name); + if (r == ARCHIVE_FATAL && errno == ENOMEM) + __archive_errx(1, "No memory"); + return (r); } /* @@ -1328,7 +1333,11 @@ archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type, const wchar_t * archive_entry_acl_text_w(struct archive_entry *entry, int flags) { - return archive_acl_text_w(entry->archive, &entry->acl, flags); + const wchar_t *r; + r = archive_acl_text_w(entry->archive, &entry->acl, flags); + if (r == NULL && errno == ENOMEM) + __archive_errx(1, "No memory"); + return (r); } const char * @@ -1337,7 +1346,7 @@ archive_entry_acl_text(struct archive_entry *entry, int flags) const char *p; if (archive_acl_text_l(&entry->acl, flags, &p, NULL, NULL) != 0 && errno == ENOMEM) - return (NULL); + __archive_errx(1, "No memory"); return (p); } diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index 24e6fe71e..7760ad734 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -2572,7 +2572,7 @@ set_acl(struct archive_write_disk *a, int fd, const char *name, acl_t acl; acl_entry_t acl_entry; acl_permset_t acl_permset; - int ret; + int ret, r; int ae_type, ae_permset, ae_tag, ae_id; uid_t ae_uid; gid_t ae_gid; @@ -2584,9 +2584,9 @@ set_acl(struct archive_write_disk *a, int fd, const char *name, if (entries == 0) return (ARCHIVE_OK); acl = acl_init(entries); - while (archive_acl_next(&a->archive, abstract_acl, + while ((r = archive_acl_next(&a->archive, abstract_acl, ae_requested_type, &ae_type, &ae_permset, &ae_tag, &ae_id, - &ae_name) == ARCHIVE_OK) { + &ae_name)) == ARCHIVE_OK) { acl_create_entry(&acl, &acl_entry); switch (ae_tag) { @@ -2628,6 +2628,12 @@ set_acl(struct archive_write_disk *a, int fd, const char *name, if (ae_permset & ARCHIVE_ENTRY_ACL_READ) acl_add_perm(acl_permset, ACL_READ); } + if (r == ARCHIVE_FATAL) { + acl_free(acl); + archive_set_error(&a->archive, errno, + "Failed to archive_acl_next"); + return (r); + } /* Try restoring the ACL through 'fd' if we can. */ #if HAVE_ACL_SET_FD