Referring: libnodave 0.8.4.4
The situation:
After establishing a TCP connection to the PLC with libnodave, I pull the network cable of the PLC to find out what happens if the network breaks down. Then I try to request some diagnostic data (SZL) from the PLC. However, there is a segmentation fault in function daveReadSZL() in line 1106, namely in the memcpy() command:
if (cpylen > 0) memcpy((uc *)buffer+len,p2.udata,cpylen);
What happens?
daveBuildAndSendPDU() returns -1250/daveResTimeout. We can prevent the segmentation fault if we check in daveReadSZL() the value of
res=daveBuildAndSendPDU(dc, &p2, pa, sizeof(pa), da, sizeof(da));
BEFORE entering the while loop.
So the solution of the problem is quite simple. We just add this comparison before the "while (p2.param[9]!=0) ..." loop, for instance in line 1098:
if (res < daveResOK)
return res;
That's it! There is no more segmentation fault that crashes the program.
Would be great if you could take over this bugfix into the official sources of libnodave.
Cheers, Natalie