mz-automation / libiec61850

Official repository for libIEC61850, the open-source library for the IEC 61850 protocols
http://libiec61850.com/libiec61850
GNU General Public License v3.0
878 stars 468 forks source link

SEGV in function memcpyReverseByteOrder #131

Closed HopefulWei closed 5 years ago

HopefulWei commented 5 years ago

I used gcc 5.4 and AddressSanitizer(export CFLAGS="-g -fsanitize=address" CXXFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" before make) to build libiec61850. First, I run the server_example_61400_25 in directory libiec61850/examples/server_example_61400_25 by command sudo ./server_example_61400_25 so that the server is set up. Then I tested iec61850_client_example_log in directory libiec61850/examples/iec61850_client_example_log by command sudo ./iec61850_client_example_log. But I got SEGV in function memcpyReverseByteOrder in conversions.c. This is the ASAN information:

ASAN:SIGSEGV
=================================================================
==63==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x00000043d461 bp 0x7ffd36addb30 sp 0x7ffd36addb30 T0)
    #0 0x43d460 in memcpyReverseByteOrder src/common/conversions.c:274
    #1 0x40eaca in MmsValue_getUtcTimeInMs src/mms/iso_mms/common/mms_value.c:772
    #2 0x402780 in main /home/gw/share/libiec61850-1.3.2/examples/iec61850_client_example_log/client_example_log.c:104
    #3 0x7fd892d7382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #4 0x4020e8 n _start (/home/gw/share/libiec61850-1.3.2/examples/iec61850_client_example_log/client_example_log+0x4020e8)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV src/common/conversions.c:274 memcpyReverseByteOrder
==63==ABORTING

This is the gdb8.0.1's information:

Thread 2 received signal SIGSEGV, Segmentation fault.
0x0000736e in memcpyReverseByteOrder (dst=0xbffff564 "", src=0x5 <error: Cannot access memory at address 0x5>, size=4) at src/common/conversions.c:274
274         dst[i] = src[size - i - 1];

version 1.3.2/1.3.1/1.3.0 has the problem.

The normal operation error is

LCB values: error 10
Segmentation fault: 11
HopefulWei commented 5 years ago

Iec61850_client_example_log has the same problem when other server is running.

mzillgith commented 5 years ago

The example is only intended to run with server_example_logging. I will add some error handling to the example in the next library version to avoid confusion.