]> git.ipfire.org Git - pakfire.git/commitdiff
xfer: Only call linkat() with a valid file descriptor
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 31 Dec 2024 14:03:56 +0000 (14:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 31 Dec 2024 14:03:56 +0000 (14:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/xfer.c

index d5d014b5b3af019c858be2b64fdc01851ec3597d..9cc8fda275a44a1d8ae0e22449457a1b5dee7736 100644 (file)
@@ -1147,12 +1147,19 @@ static int pakfire_xfer_save(struct pakfire_xfer* xfer) {
                        ERROR(xfer->ctx, "Could not link destination file %s: %m\n", xfer->path);
                        return r;
                }
-       } else {
+
+       // Link the file descriptor
+       } else if (fd >= 0) {
                r = linkat(fd, "", AT_FDCWD, xfer->path, AT_EMPTY_PATH);
                if (r) {
                        ERROR(xfer->ctx, "Could not link destination file %s: %m\n", xfer->path);
                        return r;
                }
+
+       // Fail if we don't know how to link the destination file
+       } else {
+               ERROR(xfer->ctx, "Don't know how to write to the destination file\n");
+               return -ENOTSUP;
        }
 
        return 0;