]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Eliminate invoking __archive_errx() from archive_acl.c.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 23 Jan 2012 09:55:01 +0000 (04:55 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 23 Jan 2012 09:55:01 +0000 (04:55 -0500)
SVN-Revision: 4195

libarchive/archive_acl.c
libarchive/archive_entry.c
libarchive/archive_write_disk_posix.c

index 6fccd25ff16637e4bf3576da5b61a6678e8359f9..e4ce90d0e4433c7a52adf25a8481323730519b90 100644 (file)
@@ -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,
index 4153dcd8488c7ff1e98c8629548c0b1587e9819c..b531c77d21268e60066e5cb48c675ecdf2c68bf2 100644 (file)
@@ -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);
 }
 
index 24e6fe71e6400b57dc5cf98e94fdc811c2da2d31..7760ad734c0e7b65fb2d3bf38b4dbe880f81cfb5 100644 (file)
@@ -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