From e457ea768880149b259429c836b2260f0a2c6b8f Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Fri, 17 Oct 2025 02:26:24 +0300 Subject: [PATCH] nix {cat,ls}: Add back missing checks for file descriptors I didn't catch this during the review of https://github.com/NixOS/nix/pull/14273. This fixes that mistake. --- src/nix/cat.cc | 2 ++ src/nix/ls.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/nix/cat.cc b/src/nix/cat.cc index 5b93d560b..1284b50fd 100644 --- a/src/nix/cat.cc +++ b/src/nix/cat.cc @@ -76,6 +76,8 @@ struct CmdCatNar : StoreCommand, MixCat void run(ref store) override { AutoCloseFD fd = open(narPath.c_str(), O_RDONLY); + if (!fd) + throw SysError("opening NAR file '%s'", narPath); auto source = FdSource{fd.get()}; auto narAccessor = makeNarAccessor(source); auto listing = listNar(narAccessor, CanonPath::root, true); diff --git a/src/nix/ls.cc b/src/nix/ls.cc index 846af246d..82721222e 100644 --- a/src/nix/ls.cc +++ b/src/nix/ls.cc @@ -146,6 +146,8 @@ struct CmdLsNar : Command, MixLs void run() override { AutoCloseFD fd = open(narPath.c_str(), O_RDONLY); + if (!fd) + throw SysError("opening NAR file '%s'", narPath); auto source = FdSource{fd.get()}; auto narAccessor = makeNarAccessor(source); auto listing = listNar(narAccessor, CanonPath::root, true);