Skip to content

Commit 3c03050

Browse files
authored
Merge pull request #14290 from NixOS/dont-write-nar-to-tty
nix store dump-path: Refuse to write NARs to the terminal
2 parents b56e456 + 109f644 commit 3c03050

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/nix/dump-path.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
using namespace nix;
66

7+
static FdSink getNarSink()
8+
{
9+
auto fd = getStandardOutput();
10+
if (isatty(fd))
11+
throw UsageError("refusing to write NAR to a terminal");
12+
return FdSink(std::move(fd));
13+
}
14+
715
struct CmdDumpPath : StorePathCommand
816
{
917
std::string description() override
@@ -20,7 +28,7 @@ struct CmdDumpPath : StorePathCommand
2028

2129
void run(ref<Store> store, const StorePath & storePath) override
2230
{
23-
FdSink sink(getStandardOutput());
31+
auto sink = getNarSink();
2432
store->narFromPath(storePath, sink);
2533
sink.flush();
2634
}
@@ -51,7 +59,7 @@ struct CmdDumpPath2 : Command
5159

5260
void run() override
5361
{
54-
FdSink sink(getStandardOutput());
62+
auto sink = getNarSink();
5563
dumpPath(path, sink);
5664
sink.flush();
5765
}

0 commit comments

Comments
 (0)