From 4a3546153cd0598bd8f992a0d2a2eea985e0acac Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 31 Dec 2024 14:03:56 +0000 Subject: [PATCH] xfer: Only call linkat() with a valid file descriptor Signed-off-by: Michael Tremer --- src/libpakfire/xfer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/xfer.c b/src/libpakfire/xfer.c index d5d014b5b..9cc8fda27 100644 --- a/src/libpakfire/xfer.c +++ b/src/libpakfire/xfer.c @@ -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; -- 2.47.3