]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Introduce add_pax_attr_binary and have add_pax_attr call it
authorStefan Berger <stefanb@us.ibm.com>
Fri, 6 May 2016 18:34:01 +0000 (14:34 -0400)
committerStefan Berger <stefanb@linux.vnet.ibm.com>
Mon, 9 Jan 2017 01:31:14 +0000 (20:31 -0500)
To prepare for being able to write binary values in the PAX extended
header, introduce add_pax_attr_binary and have add_pax_attr call it
by determining the length of the string being passed.

libarchive/archive_write_set_format_pax.c

index 0063d23e1d2a8783538c3cd6c23c359dfc33300b..0c5322d485d92a3718c8065a47d209ffe3bb7f55 100644 (file)
@@ -66,6 +66,9 @@ struct pax {
 
 static void             add_pax_attr(struct archive_string *, const char *key,
                             const char *value);
+static void             add_pax_attr_binary(struct archive_string *,
+                            const char *key,
+                            const char *value, size_t value_len);
 static void             add_pax_attr_int(struct archive_string *,
                             const char *key, int64_t value);
 static void             add_pax_attr_time(struct archive_string *,
@@ -274,6 +277,17 @@ add_pax_attr_int(struct archive_string *as, const char *key, int64_t value)
  */
 static void
 add_pax_attr(struct archive_string *as, const char *key, const char *value)
+{
+       add_pax_attr_binary(as, key, value, strlen(value));
+}
+
+/*
+ * Add a key/value attribute to the pax header.  This function handles
+ * binary values.
+ */
+static void
+add_pax_attr_binary(struct archive_string *as, const char *key,
+                   const char *value, size_t value_len)
 {
        int digits, i, len, next_ten;
        char tmp[1 + 3 * sizeof(int)];  /* < 3 base-10 digits per byte */
@@ -282,7 +296,7 @@ add_pax_attr(struct archive_string *as, const char *key, const char *value)
         * PAX attributes have the following layout:
         *     <len> <space> <key> <=> <value> <nl>
         */
-       len = 1 + (int)strlen(key) + 1 + (int)strlen(value) + 1;
+       len = 1 + (int)strlen(key) + 1 + (int)value_len + 1;
 
        /*
         * The <len> field includes the length of the <len> field, so
@@ -313,7 +327,7 @@ add_pax_attr(struct archive_string *as, const char *key, const char *value)
        archive_strappend_char(as, ' ');
        archive_strcat(as, key);
        archive_strappend_char(as, '=');
-       archive_strcat(as, value);
+       archive_array_append(as, value, value_len);
        archive_strappend_char(as, '\n');
 }