From: Michael Tremer Date: Tue, 31 Dec 2024 14:03:56 +0000 (+0000) Subject: xfer: Only call linkat() with a valid file descriptor X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a3546153cd0598bd8f992a0d2a2eea985e0acac;p=people%2Fric9%2Fpakfire.git xfer: Only call linkat() with a valid file descriptor Signed-off-by: Michael Tremer --- 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;