From 2330b1386499ef99169d06614fb086920cdf564c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Aug 2015 10:17:22 +0200 Subject: [PATCH] Fix coverity reported strcat/strcpy potential overflows --- common/fpid.cpp | 2 +- gerbview/rs274x.cpp | 5 ++++- pcbnew/legacy_netlist_reader.cpp | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/common/fpid.cpp b/common/fpid.cpp index 025b7b57e4..1ed0f991db 100644 --- a/common/fpid.cpp +++ b/common/fpid.cpp @@ -97,7 +97,7 @@ static int okRevision( const std::string& aField ) if( aField.size() >= 4 ) { strcpy( rev, "x/" ); - strcat( rev, aField.c_str() ); + strncat( rev, aField.c_str(), sizeof(rev)-strlen(rev)-1 ); if( EndsWithRev( rev, rev + strlen(rev), '/' ) == rev+2 ) return -1; // success diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index d30ee3acdd..b8eb6c7577 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -597,7 +597,10 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, ReportMessage( _( "Too many include files!!" ) ); break; } - strcpy( line, text ); + + strncpy( line, text, sizeof(line)-1 ); + line[sizeof(line)-1] = '\0'; + strtok( line, "*%%\n\r" ); m_FilesList[m_FilesPtr] = m_Current_File; diff --git a/pcbnew/legacy_netlist_reader.cpp b/pcbnew/legacy_netlist_reader.cpp index 4c769d2716..a559c7b6ba 100644 --- a/pcbnew/legacy_netlist_reader.cpp +++ b/pcbnew/legacy_netlist_reader.cpp @@ -108,7 +108,8 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText ) wxString name; // the name of component that was placed in the schematic char line[1024]; - strcpy( line, aText ); + strncpy( line, aText, sizeof(line)-1 ); + line[sizeof(line)-1] = '\0'; value = wxT( "~" );