Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory corrupted after "Clock synchronization command" #112

Open
sdelcc opened this issue Apr 14, 2022 · 3 comments
Open

Memory corrupted after "Clock synchronization command" #112

sdelcc opened this issue Apr 14, 2022 · 3 comments

Comments

@sdelcc
Copy link

sdelcc commented Apr 14, 2022

File : cs104_slave.c

Hi,

When receiving "Clock synchronization command" (C_CS_NA_1),
if 'slave->clockSyncHandler(...)' callback returns 'true',
then :
actions performed to build ASDU response leads to a memory corruption
and a crash few minutes later when using memory...

See Valgrind traces below :

==18912== Thread 32:
==18912== Invalid write of size 1
==18912== at 0x4C6E9E5: CS101_ASDU_addInformationObject (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C81E64: handleASDU (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C82511: handleMessage (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C8348E: MasterConnection_handleTcpConnection (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C8366A: handleClientConnections (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C83A73: handleConnectionsThreadless (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C841D7: CS104_Slave_tick (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x196B52: CInterfaceLib60870::Work() (interfacelib60870.cpp:340)
==18912== by 0x184D83: CTache60870Serveur::Executer(SKEventList) (tache60870serveur.cpp:167)
==18912== by 0x28D7A9: Tache::Body() (tache.cpp:153)
==18912== by 0x30EF89: body(void*) (Task.cpp:479)
==18912== by 0x49944F7: start_thread (pthread_create.c:456)
==18912== Address 0x941d82c is 0 bytes after a block of size 20 alloc'd
==18912== at 0x482D5DC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==18912== by 0x4C89942: Memory_malloc (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C6E8B4: CS101_ASDU_createFromBuffer (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C824FD: handleMessage (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C8348E: MasterConnection_handleTcpConnection (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C8366A: handleClientConnections (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C83A73: handleConnectionsThreadless (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x4C841D7: CS104_Slave_tick (in /usr/lib/liblib60870.so.2.1.1)
==18912== by 0x196B52: CInterfaceLib60870::Work() (interfacelib60870.cpp:340)
==18912== by 0x184D83: CTache60870Serveur::Executer(SKEventList) (tache60870serveur.cpp:167)
==18912== by 0x28D7A9: Tache::Body() (tache.cpp:153)
==18912== by 0x30EF89: body(void*) (Task.cpp:479)

Issue seems to be localized in CS101_ASDU_addInformationObject() call.

Regards,

@mzillgith
Copy link
Contributor

Hi,
I tried to reproduce this with the provided exampe (lib60870-C/examples/cs104_server/simple_server.c) but I was not able to do so. I didn't observe this problem. Can you provide more context information? E.g. what is your environment, did you do anything with the ASDU inside of the callback handler?

@sdelcc
Copy link
Author

sdelcc commented Apr 14, 2022 via email

@mzillgith
Copy link
Contributor

I didn't find anything. It seems you are using an older version. Can you update to 2.3.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants