]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Sanity-check pakfire-format
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jul 2021 11:30:58 +0000 (11:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jul 2021 11:30:58 +0000 (11:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c

index 9f7e370853e7f82a898ba7d29f21c53e43dfc918..51f97fd753ff85651cb9f57958740e9658b510b8 100644 (file)
@@ -645,6 +645,23 @@ static int pakfire_archive_read_format(PakfireArchive archive, struct archive* a
                goto ERROR;
        }
 
+       const char* entry_name = archive_entry_pathname(entry);
+
+       // Check for filename (must be "pakfire-format")
+       if (strcmp(entry_name, "pakfire-format") != 0) {
+               DEBUG(archive->pakfire, "First file is not named \"pakfire-format\"");
+               r = 1;
+               goto ERROR;
+       }
+
+       // The file cannot be larger than a couple of bytes
+       size = archive_entry_size(entry);
+       if (size == 0 || size >= 128) {
+               DEBUG(archive->pakfire, "pakfire-format is of an invalid size: %zu bytes\n", size);
+               r = 1;
+               goto ERROR;
+       }
+
        // Read the entire payload
        r = pakfire_archive_copy_data_to_buffer(archive->pakfire, a, entry, &data, &size);
        if (r) {
@@ -664,7 +681,7 @@ ERROR:
        if (data)
                free(data);
 
-       return 0;
+       return r;
 }
 
 static int pakfire_archive_try_open(PakfireArchive archive, const char* path) {