← Back to team overview

kicad-developers team mailing list archive

Patch: Prevent pcbnew crash on malformed remote command

 

Problem: Malformed commands sent to pcbnew over the socket connection can cause pcbnew to crash.

To Reproduce:
a) Start pcbnew. Do not start eeschema.
b) telnet localhost 4242
c) Type "Enter".
d) pcbnew crashes

Root cause: strtok() returns a NULL pointer if no more tokens can be found. Passing a NULL pointer to strcmp() causes a crash due to an attempt to dereference the NULL pointer.

Patch:

diff -c "c:/kicad-dev/pcbnew/controle.cpp~" "c:/kicad-dev/pcbnew/controle.cpp"
*** c:/kicad-dev/pcbnew/controle.cpp~ Sun Apr 2 14:05:23 2006
--- c:/kicad-dev/pcbnew/controle.cpp Mon Apr 3 23:22:23 2006
***************
*** 34,40 ****

idcmd = strtok(Line," \n\r");
text = strtok(NULL," \n\r");
! if( strcmp(idcmd,"$PART:") == 0)
{
MODULE * Module;
msg = CONV_FROM_UTF8(text);
--- 34,40 ----

idcmd = strtok(Line," \n\r");
text = strtok(NULL," \n\r");
! if(idcmd && strcmp(idcmd,"$PART:") == 0)
{
MODULE * Module;
msg = CONV_FROM_UTF8(text);
***************
*** 53,59 ****
}
}

! if( strcmp(idcmd,"$PIN:") == 0)
{
wxString PinName, ModName;
MODULE * Module;
--- 53,59 ----
}
}

! if(idcmd && strcmp(idcmd,"$PIN:") == 0)
{
wxString PinName, ModName;
MODULE * Module;
***************
*** 61,67 ****
int netcode = -1;
PinName = CONV_FROM_UTF8(text);
text = strtok(NULL," \n\r");
! if( strcmp(text, "$PART:") == 0 ) text = strtok(NULL,"\n\r");

wxClientDC dc(frame->DrawPanel);
frame->DrawPanel->PrepareGraphicContext(&dc);
--- 61,67 ----
int netcode = -1;
PinName = CONV_FROM_UTF8(text);
text = strtok(NULL," \n\r");
! if(text && strcmp(text, "$PART:") == 0 ) text = strtok(NULL,"\n\r");

wxClientDC dc(frame->DrawPanel);
frame->DrawPanel->PrepareGraphicContext(&dc);