From afd89c358ea399f8a9873b34b3a5594e537c67f3 Mon Sep 17 00:00:00 2001 From: Andrew Zonenberg Date: Tue, 12 Aug 2014 09:39:44 -0500 Subject: [PATCH] 1) EDA_DRAW_FRAME::m_showOriginAxis is never initialized in the constructor 2) LIB_RECTANGLE and related classes sscanf data read from a file using "%s" without field limits, which can cause problems with malformed/really long inputs. 3) If some of the optional fields in a lib line are missing, "tmp" can remain uninitialized. --- common/draw_frame.cpp | 1 + eeschema/lib_arc.cpp | 4 ++-- eeschema/lib_rectangle.cpp | 4 ++-- eeschema/lib_text.cpp | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index fe259933b4..840f498ad8 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -113,6 +113,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, m_showAxis = false; // true to draw axis. m_showBorderAndTitleBlock = false; // true to display reference sheet. m_showGridAxis = false; // true to draw the grid axis + m_showOriginAxis = false; // true to draw the grid origin m_cursorShape = 0; m_LastGridSizeId = 0; m_DrawGrid = true; // hide/Show grid. default = show diff --git a/eeschema/lib_arc.cpp b/eeschema/lib_arc.cpp index 686adbf8c0..fa5e1a42bc 100644 --- a/eeschema/lib_arc.cpp +++ b/eeschema/lib_arc.cpp @@ -122,10 +122,10 @@ bool LIB_ARC::Save( OUTPUTFORMATTER& aFormatter ) bool LIB_ARC::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) { int startx, starty, endx, endy, cnt; - char tmp[256]; + char tmp[256] = ""; char* line = (char*) aLineReader; - cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %d %s %d %d %d %d", + cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %d %255s %d %d %d %d", &m_Pos.x, &m_Pos.y, &m_Radius, &m_t1, &m_t2, &m_Unit, &m_Convert, &m_Width, tmp, &startx, &starty, &endx, &endy ); if( cnt < 8 ) diff --git a/eeschema/lib_rectangle.cpp b/eeschema/lib_rectangle.cpp index 057b049eb1..451fb7e158 100644 --- a/eeschema/lib_rectangle.cpp +++ b/eeschema/lib_rectangle.cpp @@ -67,10 +67,10 @@ bool LIB_RECTANGLE::Save( OUTPUTFORMATTER& aFormatter ) bool LIB_RECTANGLE::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) { int cnt; - char tmp[256]; + char tmp[256] = ""; char* line = (char*)aLineReader; - cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y, + cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %255s", &m_Pos.x, &m_Pos.y, &m_End.x, &m_End.y, &m_Unit, &m_Convert, &m_Width, tmp ); if( cnt < 7 ) diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 1b51b0f4e9..b1e3eb0837 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -98,7 +98,7 @@ bool LIB_TEXT::Save( OUTPUTFORMATTER& aFormatter ) bool LIB_TEXT::Load( LINE_READER& aLineReader, wxString& errorMsg ) { - int cnt, thickness; + int cnt, thickness = 0; char hjustify = 'C', vjustify = 'C'; char buf[256]; char tmp[256]; @@ -108,7 +108,7 @@ bool LIB_TEXT::Load( LINE_READER& aLineReader, wxString& errorMsg ) buf[0] = 0; tmp[0] = 0; // For italic option, Not in old versions - cnt = sscanf( line + 2, "%lf %d %d %d %d %d %d \"%[^\"]\" %s %d %c %c", + cnt = sscanf( line + 2, "%lf %d %d %d %d %d %d \"%[^\"]\" %255s %d %c %c", &angle, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs, &m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify, &vjustify ); @@ -122,7 +122,7 @@ bool LIB_TEXT::Load( LINE_READER& aLineReader, wxString& errorMsg ) } else { - cnt = sscanf( line + 2, "%lf %d %d %d %d %d %d %s %s %d %c %c", + cnt = sscanf( line + 2, "%lf %d %d %d %d %d %d %255s %255s %d %c %c", &angle, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs, &m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify, &vjustify );