From 351dbdfdca55d949ba3ff09d8c36a5d47c4da722 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 9 Apr 2026 17:00:00 -0400 Subject: [PATCH] libcstore: Fix null deref in writeDebugInfo for non-directory NARs When index-debug-info is enabled and the store path being copied is a regular file (not a directory), std::get_if returns nullptr since the NAR root is a File variant. The loop then immediately dereferences buildIdDir->contents on the null pointer, causing a segfault. Add a null check at the top of the loop to break early when the NAR root is not a directory. Change-Id: I3a6e792b84cc12c837ecaddf4fee889e1bcb6397 (cherry picked from commit 6c7ccc25883a3e7a4b5d17186487228baaa13c37) --- lix/libstore/binary-cache-store.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/lix/libstore/binary-cache-store.cc b/lix/libstore/binary-cache-store.cc index 6e14cf4ad..c3eb0a4c5 100644 --- a/lix/libstore/binary-cache-store.cc +++ b/lix/libstore/binary-cache-store.cc @@ -221,6 +221,7 @@ try { auto * buildIdDir = std::get_if(&narIndex); for (auto subdir : { "lib", "debug", ".build-id" }) { + if (!buildIdDir) break; // get returns nullptr subdir does not exist, and std::get_if propagates it. buildIdDir = std::get_if(get(buildIdDir->contents, subdir)); }