From 0e9c8a42380be0d2f9dec6aa5c25c4247d0dbfbd Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 8 Jan 2018 17:33:01 -0500 Subject: [PATCH] Prevent segfault when remapping project with corrupt cache library. Use the symbol found in the library when the symbol is not in the cache library. Add an assert to prevent dereferncing a null pointer in the future even thought this should not happen as the rescue algorithm does not add a candidate when a symbol cannot be found in either the cache or any other library. Fixes lp:1741964 https://bugs.launchpad.net/kicad/+bug/1741964 --- eeschema/project_rescue.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index 8407215273..35105c20be 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Chris Pavlina - * Copyright (C) 2015-2017 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2015-2018 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -295,7 +295,11 @@ wxString RESCUE_CACHE_CANDIDATE::GetActionDescription() const bool RESCUE_CACHE_CANDIDATE::PerformAction( RESCUER* aRescuer ) { - LIB_PART new_part( *m_cache_candidate ); + LIB_PART* tmp = ( m_cache_candidate ) ? m_cache_candidate : m_lib_candidate; + + wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." ); + + LIB_PART new_part( *tmp ); new_part.SetName( m_new_name ); new_part.RemoveAllAliases(); aRescuer->AddPart( &new_part ); @@ -410,7 +414,11 @@ wxString RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription() const bool RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction( RESCUER* aRescuer ) { - LIB_PART new_part( *m_cache_candidate ); + LIB_PART* tmp = ( m_cache_candidate ) ? m_cache_candidate : m_lib_candidate; + + wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." ); + + LIB_PART new_part( *tmp ); new_part.SetName( m_new_id.GetLibItemName() ); new_part.RemoveAllAliases(); aRescuer->AddPart( &new_part );