]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
libarchive: Fix format string issues 3180/head
authorDag-Erling Smørgrav <des@des.dev>
Wed, 24 Jun 2026 15:58:29 +0000 (17:58 +0200)
committerDag-Erling Smørgrav <des@des.dev>
Wed, 24 Jun 2026 16:25:01 +0000 (18:25 +0200)
libarchive/archive_write_set_format_xar.c
libarchive/test/test_read_format_zip_zipx_encrypted.c

index 98bc4952dad98a2f0b55ce001a184ad7efa6c901..4478ceb588e2091c3816d2d025e186d6b0302921 100644 (file)
@@ -111,7 +111,7 @@ static int xml_writer_start_element(struct xml_writer *ctx,
 static int xml_writer_write_attribute(struct xml_writer *ctx, const char *key,
     const char *value);
 static int xml_writer_write_attributef(struct xml_writer *ctx, const char *key,
-    const char *format, ...);
+    const char *format, ...) __LA_PRINTF(3, 4);
 static int xml_writer_write_string(struct xml_writer *ctx, const char *string);
 static int xml_writer_write_base64(struct xml_writer* ctx,
     const char *data, size_t start, size_t len);
@@ -907,7 +907,7 @@ xmlwrite_string(struct archive_write *a, struct xml_writer *writer,
        return (ARCHIVE_OK);
 }
 
-static int
+static int __LA_PRINTF(4, 5)
 xmlwrite_fstring(struct archive_write *a, struct xml_writer *writer,
        const char *key, const char *fmt, ...)
 {
@@ -1333,11 +1333,11 @@ make_file_entry(struct archive_write *a, struct xml_writer *writer,
                        return (ARCHIVE_FATAL);
                }
                r = xmlwrite_fstring(a, writer, "major",
-                   "%d", archive_entry_rdevmajor(file->entry));
+                   "%ld", (long)archive_entry_rdevmajor(file->entry));
                if (r < 0)
                        return (ARCHIVE_FATAL);
                r = xmlwrite_fstring(a, writer, "minor",
-                   "%d", archive_entry_rdevminor(file->entry));
+                   "%ld", (long)archive_entry_rdevminor(file->entry));
                if (r < 0)
                        return (ARCHIVE_FATAL);
                r = xml_writer_end_element(writer);
@@ -1361,7 +1361,7 @@ make_file_entry(struct archive_write *a, struct xml_writer *writer,
                return (ARCHIVE_FATAL);
        if (archive_entry_dev(file->entry) != 0) {
                r = xmlwrite_fstring(a, writer, "deviceno",
-                   "%d", archive_entry_dev(file->entry));
+                   "%ld", (long)archive_entry_dev(file->entry));
                if (r < 0)
                        return (ARCHIVE_FATAL);
        }
index 5349ba1995f70705865a8368621bd90d823dcf8d..f07e1e5c3129d023e4abe86e3280e5a16daaa915 100644 (file)
@@ -56,7 +56,7 @@ static la_ssize_t read_streaming_buffer(struct archive *a, void *_client_data, c
 }
 
 static void
-validate_entry_read(struct archive *a, const char* msg, const int streaming_reader)
+validate_entry_read(struct archive *a, const int streaming_reader)
 {
        struct archive_entry *ae;
        size_t total_read;
@@ -76,7 +76,8 @@ validate_entry_read(struct archive *a, const char* msg, const int streaming_read
                r = archive_read_data(a, readbuf, sizeof(readbuf));
                if (r <= 0) {
                        if (r < 0) {
-                               failure(msg, (int) r, archive_error_string(a));
+                               failure("archive_read_data returned %d: %s",
+                                   (int)r, archive_error_string(a));
                                assertEqualInt(r > 0, 1);
                        }
                        break;
@@ -114,7 +115,7 @@ test_encrypted_zipx_read_mem(char* buff, size_t used)
        assertEqualIntA(a, ARCHIVE_OK, archive_read_add_passphrase(a, password));
        assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used));
 
-       validate_entry_read(a, "archive_read_data returned %d: %s", 0);
+       validate_entry_read(a, 0);
 
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
@@ -126,7 +127,7 @@ test_encrypted_zipx_read_mem(char* buff, size_t used)
        assertEqualIntA(a, ARCHIVE_OK, archive_read_add_passphrase(a, password));
        assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
 
-       validate_entry_read(a, "seek: archive_read_data returned %d: %s", 0);
+       validate_entry_read(a, 0);
 
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
@@ -144,7 +145,7 @@ test_encrypted_zipx_read_callback(const char* buff, const size_t used)
        assertEqualIntA(a, ARCHIVE_OK, archive_read_add_passphrase(a, password));
        /* NOTE: archive_read_open2 with read callback only -> NON-seekable. */
        assertEqualIntA(a, ARCHIVE_OK, archive_read_open2(a, &stream_buffer, NULL, read_streaming_buffer, NULL, NULL));
-       validate_entry_read(a, "archive_read_data returned %d: %s", 1);
+       validate_entry_read(a, 1);
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 }