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
This commit is contained in:
Seth Hillbrand
2026-03-02 07:48:53 -08:00
parent d1f767ee3f
commit 508bb36f8b
+18 -3
View File
@@ -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 );
}