]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Give the API caller a memory allocation failure of a string conversion object by...
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 4 Apr 2011 07:12:16 +0000 (03:12 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 4 Apr 2011 07:12:16 +0000 (03:12 -0400)
instead of use of __archive_errx().

SVN-Revision: 3156

libarchive/archive_read_support_format_cab.c
libarchive/archive_read_support_format_iso9660.c
libarchive/archive_read_support_format_lha.c
libarchive/archive_read_support_format_tar.c
libarchive/archive_read_support_format_xar.c
libarchive/archive_read_support_format_zip.c
libarchive/archive_string.c
libarchive/archive_write_set_format_iso9660.c
libarchive/archive_write_set_format_pax.c

index a80ad545d26338a684bd17f854b4034e13d5f686..79da9bb0151faf5e68ebb5c8b273b645d87929be 100644 (file)
@@ -803,10 +803,13 @@ cab_read_header(struct archive_read *a)
                        goto invalid;
                archive_string_init(&(file->pathname));
                if ((file->attr & ATTR_NAME_IS_UTF) && cab->sconv == NULL) {
-                       if (cab->sconv_utf8 == NULL)
+                       if (cab->sconv_utf8 == NULL) {
                                cab->sconv_utf8 =
                                    archive_string_conversion_from_charset(
                                        &(a->archive), "UTF-8", 1);
+                               if (cab->sconv_utf8 == NULL)
+                                       return (ARCHIVE_FATAL);
+                       }
                        archive_strncpy_in_locale(&(file->pathname), p, len,
                            cab->sconv_utf8);
                } else
index 1f288694e822eee0b8cf01491df7226cf09b5bfd..f0ba7955a1403bda8a83ae0736f75ce0f08f4fff 100644 (file)
@@ -1802,10 +1802,13 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
 
                /* Convert UTF-16BE of a filename to local locale MBS and store
                 * the result into a filename field. */
-               if (iso9660->sconv_utf16be == NULL)
+               if (iso9660->sconv_utf16be == NULL) {
                        iso9660->sconv_utf16be =
                            archive_string_conversion_from_charset(
                                &(a->archive), "UTF-16BE", 1);
+                       if (iso9660->sconv_utf16be == NULL)
+                               return (NULL);/* Coundn't allocate memory */
+               }
                archive_strncpy_in_locale(&file->name,
                    (const char *)p, name_len, iso9660->sconv_utf16be);
        } else {
index ecf9584743d7228625c97737635c7fc106606a15..bb482f912102030ad82407106061433f5f675d21 100644 (file)
@@ -1280,6 +1280,8 @@ lha_read_file_extended_header(struct archive_read *a, struct lha *lha,
                                        lha->sconv =
                                            archive_string_conversion_from_charset(
                                                &(a->archive), charset, 1);
+                                       if (lha->sconv == NULL)
+                                               return (ARCHIVE_FATAL);
                                }
                        }
                        break;
index a464637e5ef924c344facc48fc67457017012e7f..4d75121c8487eb575e982cb37ec866b97cdd8612 100644 (file)
@@ -889,9 +889,12 @@ header_Solaris_ACL(struct archive_read *a, struct tar *tar,
        while (*p != '\0' && p < acl + size)
                p++;
 
-       if (tar->sconv_acl == NULL)
+       if (tar->sconv_acl == NULL) {
                tar->sconv_acl = archive_string_conversion_from_charset(
                    &(a->archive), "UTF-8", 1);
+               if (tar->sconv_acl == NULL)
+                       return (ARCHIVE_FATAL);
+       }
        if (archive_strncpy_in_locale(&(tar->localname), acl, p - acl,
            tar->sconv_acl) != 0) {
                archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
@@ -1463,6 +1466,8 @@ pax_header(struct archive_read *a, struct tar *tar,
 
                /* Identify this attribute and set it in the entry. */
                err2 = pax_attribute(a, tar, entry, key, value);
+               if (err2 == ARCHIVE_FATAL)
+                       return (err2);
                err = err_combine(err, err2);
 
                /* Skip to next line */
@@ -1481,6 +1486,8 @@ pax_header(struct archive_read *a, struct tar *tar,
                 */
                sconv = archive_string_conversion_from_charset(
                    &(a->archive), "UTF-8", 1);
+               if (sconv == NULL)
+                       return (ARCHIVE_FATAL);
        }
 
        if (archive_strlen(&(tar->entry_gname)) > 0) {
@@ -1685,10 +1692,13 @@ pax_attribute(struct archive_read *a, struct tar *tar,
        case 'S':
                /* We support some keys used by the "star" archiver */
                if (strcmp(key, "SCHILY.acl.access")==0) {
-                       if (tar->sconv_acl == NULL)
+                       if (tar->sconv_acl == NULL) {
                                tar->sconv_acl =
                                    archive_string_conversion_from_charset(
                                        &(a->archive), "UTF-8", 1);
+                               if (tar->sconv_acl == NULL)
+                                       return (ARCHIVE_FATAL);
+                       }
 
                        if (archive_strcpy_in_locale(&(tar->localname),
                            value, tar->sconv_acl) != 0) {
@@ -1702,10 +1712,13 @@ pax_attribute(struct archive_read *a, struct tar *tar,
                                    tar->localname.s,
                                    ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
                } else if (strcmp(key, "SCHILY.acl.default")==0) {
-                       if (tar->sconv_acl == NULL)
+                       if (tar->sconv_acl == NULL) {
                                tar->sconv_acl =
                                    archive_string_conversion_from_charset(
                                        &(a->archive), "UTF-8", 1);
+                               if (tar->sconv_acl == NULL)
+                                       return (ARCHIVE_FATAL);
+                       }
 
                        if (archive_strcpy_in_locale(&(tar->localname),
                            value, tar->sconv_acl) != 0) {
index e34005a8796ad9c3fb6ad9cc9fdb45ae07e0de16..51c08198486d9c08c369f96b553d4b6ae7fb9ddb 100644 (file)
@@ -701,9 +701,12 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry)
 
        if (xar->offset == 0) {
                /* Create a character conversion object. */
-               if (xar->sconv == NULL)
+               if (xar->sconv == NULL) {
                        xar->sconv = archive_string_conversion_from_charset(
                            &(a->archive), "UTF-8", 1);
+                       if (xar->sconv == NULL)
+                               return (ARCHIVE_FATAL);
+               }
 
                /* Read TOC. */
                r = read_toc(a);
index a6b929a64baeffce796329fb39c1fe24d997369b..c146b9e8938a162c59fc838200b696759b6ca1ae 100644 (file)
@@ -503,10 +503,13 @@ zip_read_file_header(struct archive_read *a, struct archive_entry *entry,
        }
        if (zip->sconv == NULL && (zip->flags & ZIP_UTF8_NAME) != 0) {
                /* The filename is stored to be UTF-8. */
-               if (zip->sconv_utf8 == NULL)
+               if (zip->sconv_utf8 == NULL) {
                        zip->sconv_utf8 =
                            archive_string_conversion_from_charset(
                                &a->archive, "UTF-8", 1);
+                       if (zip->sconv_utf8 == NULL)
+                               return (ARCHIVE_FATAL);
+               }
                if (archive_strncpy_in_locale(&zip->pathname,
                    h, zip->filename_length, zip->sconv_utf8) != 0) {
                        archive_set_error(&a->archive,
index 6d04d2ef04dca609e97c604cfe86341db4926b5a..9acc918c4c9cf9daea3c833028dd4371778a29cf 100644 (file)
@@ -563,14 +563,19 @@ create_sconv_object(const char *fc, const char *tc,
 
        sc = malloc(sizeof(*sc));
        if (sc == NULL)
-               __archive_errx(1, "No memory for charset conversion object");
+               return (NULL);
        sc->next = NULL;
        sc->from_charset = strdup(fc);
-       if (sc->from_charset == NULL)
-               __archive_errx(1, "No memory for charset conversion object");
+       if (sc->from_charset == NULL) {
+               free(sc);
+               return (NULL);
+       }
        sc->to_charset = strdup(tc);
-       if (sc->to_charset == NULL)
-               __archive_errx(1, "No memory for charset conversion object");
+       if (sc->to_charset == NULL) {
+               free(sc);
+               free(sc->from_charset);
+               return (NULL);
+       }
        sc->same = (strcmp(fc, tc) == 0)?1:0;
 #if HAVE_ICONV
        sc->cd = iconv_open(tc, fc);
@@ -772,6 +777,11 @@ get_sconv_object(struct archive *a, const char *fc, const char *tc, int flag)
        else
                current_codepage = a->current_codepage;
        sc = create_sconv_object(fc, tc, current_codepage, flag);
+       if (sc == NULL) {
+               archive_set_error(a, ENOMEM,
+                   "Could not allocate memory for a string conversion object");
+               return (NULL);
+       }
 #if HAVE_ICONV
        if (sc->cd == (iconv_t)-1 && (flag & SCONV_BEST_EFFORT) == 0) {
                free_sconv_object(sc);
@@ -860,7 +870,8 @@ get_current_charset(struct archive *a)
  * Return NULL if the platform does not support the specified conversion
  * and best_effort is 0.
  * If best_effort is set, A string conversion object must be returned
- * but the conversion might fail when non-ASCII code is found.
+ * except memory allocation for the object fails, but the conversion
+ * might fail when non-ASCII code is found.
  */
 struct archive_string_conv *
 archive_string_conversion_to_charset(struct archive *a, const char *charset,
@@ -1759,6 +1770,8 @@ archive_mstring_get_utf8(struct archive *a, struct archive_mstring *aes)
 
        if (aes->aes_set & AES_SET_MBS) {
                sc = archive_string_conversion_to_charset(a, "UTF-8", 1);
+               if (sc == NULL)
+                       return (NULL);/* Couldn't allocate memory for sc. */
                r = archive_strncpy_in_locale(&(aes->aes_mbs), aes->aes_mbs.s,
                    aes->aes_mbs.length, sc);
                if (a == NULL)
@@ -1790,6 +1803,8 @@ archive_mstring_get_mbs(struct archive *a, struct archive_mstring *aes)
        /* If there's a UTF-8 form, try converting with the native locale. */
        if (aes->aes_set & AES_SET_UTF8) {
                sc = archive_string_conversion_from_charset(a, "UTF-8", 1);
+               if (sc == NULL)
+                       return (NULL);/* Couldn't allocate memory for sc. */
                r = archive_strncpy_in_locale(&(aes->aes_mbs),
                        aes->aes_utf8.s, aes->aes_utf8.length, sc);
                if (a == NULL)
@@ -1897,6 +1912,8 @@ archive_mstring_update_utf8(struct archive *a, struct archive_mstring *aes,
 
        /* Try converting UTF-8 to MBS, return false on failure. */
        sc = archive_string_conversion_from_charset(a, "UTF-8", 1);
+       if (sc == NULL)
+               return (0);/* Couldn't allocate memory for sc. */
        r = archive_strcpy_in_locale(&(aes->aes_mbs), utf8, sc);
        if (a == NULL)
                free_sconv_object(sc);
index 43fbade8002a2f9e6d3311082130ae1dce09614c..b6139a2259d7b448895dbcfccc8a8889935061ef 100644 (file)
@@ -1541,9 +1541,13 @@ iso9660_write_header(struct archive_write *a, struct archive_entry *entry)
                        iso9660->sconv_to_utf16be =
                            archive_string_conversion_to_charset(
                                &(a->archive), "UTF-16BE", 1);
+                       if (iso9660->sconv_to_utf16be == NULL)
+                               return (ARCHIVE_FATAL);/* Couldn't allocate memory */
                        iso9660->sconv_from_utf16be =
                            archive_string_conversion_from_charset(
                                &(a->archive), "UTF-16BE", 1);
+                       if (iso9660->sconv_from_utf16be == NULL)
+                               return (ARCHIVE_FATAL);/* Couldn't allocate memory */
                }
                /* Test whether a filename can be converted to UTF-16BE or not. */
                if (0 > archive_strncpy_in_locale(&iso9660->utf16be,
@@ -1790,9 +1794,13 @@ iso9660_close(struct archive_write *a)
                        iso9660->sconv_to_utf16be =
                            archive_string_conversion_to_charset(
                                &(a->archive), "UTF-16BE", 1);
+                       if (iso9660->sconv_to_utf16be == NULL)
+                               return (ARCHIVE_FATAL);/* Couldn't allocate memory */
                        iso9660->sconv_from_utf16be =
                            archive_string_conversion_from_charset(
                                &(a->archive), "UTF-16BE", 1);
+                       if (iso9660->sconv_from_utf16be == NULL)
+                               return (ARCHIVE_FATAL);/* Couldn't allocate memory */
                }
        }
 
index 0cf1e6085699afe19a1a841d960733ec09a13c0c..42b1056fa2bf71258bde746d5daace569fb5b482 100644 (file)
@@ -386,9 +386,12 @@ archive_write_pax_header(struct archive_write *a,
                return (ARCHIVE_FAILED);
        }
 
-       if (pax->sconv_utf8 == NULL)
+       if (pax->sconv_utf8 == NULL) {
                pax->sconv_utf8 = archive_string_conversion_to_charset(
                    &(a->archive), "UTF-8", 1);
+               if (pax->sconv_utf8 == NULL)
+                       return (ARCHIVE_FAILED);/* Couldn't allocate memory */
+       }
        /*
         * Choose a header encoding.
         */