On Wed, 2014-08-13 at 10:47 +0200, jp charras wrote: > Le 13/08/2014 08:52, Andrew Zonenberg a écrit : > > I was investigating some memory corruption segfaults with Valgrind and > > found that the netlist-import code in pcbnew is calling > > wxString::Printf() with a char* using the %s format specifier. > > > > While this may look right, the _() macro (through many levels of > > indirection) converts %s to %ls, which expects a wide character string. > > > > The end result is that wcslen() gets called with a char* string, fails > > to stop at the 1-byte null character, and keeps on reading off the end > > causing garbage to be strewn through memory and sometimes crash pcbnew. > > This can be fixed by forcibly converting the incoming UTF-8 string to > > wchar_t* before passing it to wxString::Printf(). > > > > The attached patch was tested on wx 2.8 on Debian 7 64-bit. I'm not sure > > if it breaks anything on Windows or wx 3.0 so please test carefully :) > > > Thanks, Andrew. > > wxString( fpOnBoard->GetFPID().GetFootprintName() ).GetData() > > instead of > wxString( fpOnBoard->GetFPID().GetFootprintName() ).wc_str() > > could be a better fix for this issue. > >
Updated patch, attached, confirmed for working without any errors on my machine. Anybody want to test on Windows or wx3.0? -- Andrew Zonenberg PhD student, security group Computer Science Department Rensselaer Polytechnic Institute http://colossus.cs.rpi.edu/~azonenberg/
=== modified file 'pcbnew/netlist.cpp'
--- pcbnew/netlist.cpp 2014-06-05 07:54:47 +0000
+++ pcbnew/netlist.cpp 2014-08-13 12:20:51 +0000
@@ -242,8 +242,8 @@
{
msg.Printf( _( "* Warning: component '%s' has footprint '%s' and should be '%s'\n" ),
GetChars( component->GetReference() ),
- fpOnBoard->GetFPID().GetFootprintName().c_str(),
- component->GetFPID().GetFootprintName().c_str() );
+ wxString( fpOnBoard->GetFPID().GetFootprintName() ).GetData(),
+ wxString( component->GetFPID().GetFootprintName() ).GetData() );
aReporter->Report( msg );
}
@@ -272,7 +272,7 @@
msg.Printf( _( "*** Warning: Component '%s' footprint ID '%s' is not "
"valid. ***\n" ),
GetChars( component->GetReference() ),
- component->GetFPID().GetFootprintName().c_str() );
+ wxString( component->GetFPID().GetFootprintName() ).GetData() );
aReporter->Report( msg );
}
@@ -294,7 +294,7 @@
msg.Printf( _( "*** Warning: component '%s' footprint '%s' was not found in "
"any libraries in the footprint library table. ***\n" ),
GetChars( component->GetReference() ),
- component->GetFPID().GetFootprintName().c_str() );
+ wxString( component->GetFPID().GetFootprintName() ).GetData() );
aReporter->Report( msg );
}
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : [email protected] Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp

