]> git.ipfire.org Git - pakfire.git/commitdiff
archive: read: Limit the maximum number of symlinks to follow
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Oct 2023 15:00:25 +0000 (15:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Oct 2023 15:00:25 +0000 (15:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c

index 85c5c228b83155671d43a6d5bcecfc80ab14badc..00a90a961f50d545a9acc0a8b721990b0898c049 100644 (file)
@@ -53,6 +53,9 @@
 
 #define MAX_SCRIPTLETS 9
 
+// The maximum number of symlinks to follow when reading a file from an archive
+#define MAX_FOLLOW_SYMLINKS 10
+
 struct pakfire_archive {
        struct pakfire* pakfire;
        int nrefs;
@@ -585,6 +588,9 @@ struct pakfire_archive_read_cookie {
 
        // Some flags
        int flags;
+
+       // Count how many symlinks we have followed
+       unsigned int followed_symlinks;
 };
 
 static ssize_t __pakfire_archive_cookie_read(void* c, char* buffer, size_t size) {
@@ -648,6 +654,12 @@ static int __pakfire_archive_read_filter(struct pakfire* pakfire, struct archive
                        if (r)
                                return PAKFIRE_WALK_ERROR;
 
+                       // Increment counter
+                       if (++cookie->followed_symlinks >= MAX_FOLLOW_SYMLINKS) {
+                               ERROR(pakfire, "Reached maximum number of symlinks to follow\n");
+                               return PAKFIRE_WALK_ERROR;
+                       }
+
                        return PAKFIRE_WALK_AGAIN;
                }