kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #00084
Patch: Prevent pcbnew crash on malformed remote command
-
To:
kicad-devel@xxxxxxxxxxxxxxx
-
From:
Mitch Bradley <wmb@...>
-
Date:
Mon, 03 Apr 2006 23:26:23 -1000
-
User-agent:
Thunderbird 1.5 (Windows/20051201)
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);