From 508bb36f8babceea74faff5bc9ad278df5ef4028 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 2 Mar 2026 07:48:53 -0800 Subject: [PATCH] Fix null dereference in PROJECT_GIT_UTILS In CLI mode, SetGitBackend() is never called so GetGitBackend() returns nullptr. GetRepositoryForFile(), CreateBranch(), and RemoveVCS() all called GetGitBackend()->method() unconditionally, causing a SIGSEGV when a schematic containing ${VCSHASH} or ${VCSSHORTHASH} text variables is loaded via kicad-cli jobset run. Fixes https://gitlab.com/kicad/code/kicad/-/issues/23214 --- common/git/project_git_utils.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/common/git/project_git_utils.cpp b/common/git/project_git_utils.cpp index 974ab1b4bd..dcc1aed273 100644 --- a/common/git/project_git_utils.cpp +++ b/common/git/project_git_utils.cpp @@ -38,20 +38,35 @@ namespace KIGIT git_repository* PROJECT_GIT_UTILS::GetRepositoryForFile( const char* aFilename ) { - return GetGitBackend()->GetRepositoryForFile( aFilename ); + GIT_BACKEND* backend = GetGitBackend(); + + if( !backend ) + return nullptr; + + return backend->GetRepositoryForFile( aFilename ); } int PROJECT_GIT_UTILS::CreateBranch( git_repository* aRepo, const wxString& aBranchName ) { - return GetGitBackend()->CreateBranch( aRepo, aBranchName ); + GIT_BACKEND* backend = GetGitBackend(); + + if( !backend ) + return -1; + + return backend->CreateBranch( aRepo, aBranchName ); } bool PROJECT_GIT_UTILS::RemoveVCS( git_repository*& aRepo, const wxString& aProjectPath, bool aRemoveGitDir, wxString* aErrors ) { - return GetGitBackend()->RemoveVCS( aRepo, aProjectPath, aRemoveGitDir, aErrors ); + GIT_BACKEND* backend = GetGitBackend(); + + if( !backend ) + return false; + + return backend->RemoveVCS( aRepo, aProjectPath, aRemoveGitDir, aErrors ); }