← Back to team overview

kicad-developers team mailing list archive

Re: wxString conversion issues in pcbnew/netlist.cpp [PATCH]

 

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.


-- 
Jean-Pierre CHARRAS


Follow ups

References