linux-can / can-tests

Linux-CAN / SocketCAN testing applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

socketCAN read() segmentation faults

vibnwis opened this issue · comments

Hi there,
Apologies if this is the right platform the issue on Linux CANSocket.

I have been experienced the segmentation faults on second frame read(). Yes, always at second frame. However, they are any frame as far as the program is concerned. I have tried to modified the code by introducing struct timeval, the timeout values. As soon as I do that, the read() throw -1 when no frames in the system buffer, or it supposes to wait till a frame is available.

here is how I open the CAN Socket. I have added many tests code to check the sanity of the CAN Socket. However, the segmentation remains. Very appreciate your comments.

m_interface = can_interface;
        m_socket_mode = mode;
        m_read_timeout_ms = read_timeout_ms;

        char buf[100];


        /* open socket */
        if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0)
        {
            perror("socketcan ");
            return STATUS_SOCKET_CREATE_ERROR;
        }


        int mtu, enable_canfd = 1; //Lim for time being not supporting CAN_FD

        struct ifreq ifr;

        strncpy(ifr.ifr_name, can_interface.c_str(), IFNAMSIZ - 1);
        ifr.ifr_name[IFNAMSIZ - 1] = '\0';


/*
 * retrieve index of the interface name
 */
        ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
        /*
         * index of the interface name
         */
        if (!ifr.ifr_ifindex) {
            perror("if_nametoindex");
            printf("Interface name %s",ifr.ifr_name);
            return STATUS_INTERFACE_NAME_TO_IDX_ERROR;
        }

        /* Check if it is required to set as FD CAN */
        if (mode == MODE_CANFD_MTU)
        {
        	/*
        	 * retrieve the interface index for the interface name (can0, can1, vcan0 etc) we wish to use.
        	 */

        	if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
        		perror("SIOCGIFINDEX");
        		return STATUS_CAN_OP_ERROR;
        	}

        	 mtu = ifr.ifr_mtu;

        	if (mtu != CANFD_MTU) {

        		printf("CAN Classic  mode");
        		return STATUS_CANFD_NOT_SUPPORTED;
        	}

        	printf("CD CAN mode");
        	/* By default it is CAN classic.
        	 *interface is ok - try to switch the socket into CAN FD mode
        	 */

        	if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES,
        	           &enable_canfd, sizeof(enable_canfd)))
        	{

        	        return STATUS_ENABLE_FD_SUPPORT_ERROR;
        	}


        }

        	/*
        		const int timestamping_flags = (SOF_TIMESTAMPING_SOFTWARE | \
            		SOF_TIMESTAMPING_RX_SOFTWARE | \
            		SOF_TIMESTAMPING_RAW_HARDWARE);

        		if (setsockopt(m_socket, SOL_SOCKET, SO_TIMESTAMPING,
            		&timestamping_flags, sizeof(timestamping_flags)) < 0) {
            		perror("setsockopt SO_TIMESTAMPING is not supported by your Linux kernel");
        		}
        	 */

        /*
         * The owner - disable default receive filter on this RAW socket
         * This is obsolete as we do not read from the socket at all, but for
         * this reason we can remove the receive list in the Kernel to save a
         * little (really a very little!) CPU usage.
         *
         * */

        /*
         #define CAN_SFF_MASK 0x000007FFU / * Standard frame format (SFF) * /
 	 	 #define CAN_EFF_MASK 0x1FFFFFFFU / * Extended frame format (EFF) * /
 	 	 #define CAN_ERR_MASK 0x1FFFFFFFU / * Ignore EFF, RTR, ERR flags * /
         */

        /* 12 Nov 20 Lim - Re-open the default receive filter on this RAW socket */
        //setsockopt(m_socket, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);  // Disable frame reception
        /*
         * A filter matches, when  <received_can_id> & mask == can_id & mask
         */


#if 0
        struct can_filter rfilter[2];
        rfilter[0].can_id   = 0x128;
        rfilter[0].can_mask = CAN_SFF_MASK;
        rfilter[1].can_id   = 0x120; 	//x120-x123
        rfilter[1].can_mask = 0x1FC;  	//001-1111-1100 eg, 0x120-0x123
#else
        /* filter incoming frames */
        struct can_filter rfilter[1];
        rfilter[0].can_id   = CAN_SFF_MASK;
        rfilter[0].can_mask = 0x123;   	// can_mask = 0, all frames pass through
#endif
        setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));

#if 0
        struct timeval timeout;

        timeout.tv_sec = 0;
        timeout.tv_usec = 1000; //m_read_timeout_ms *1000;

       // timeout.tv_usec = m_read_timeout_ms * 10;  // Not init'ing this can cause strange errors
       // if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO|SO_SNDTIMEO, (const char*)&timeout,sizeof(struct timeval)) < 0) {
        if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout,sizeof(timeout)) < 0) {
        	perror("Setting timeout failed");
        	return STATUS_SOCKET_CREATE_ERROR;
        }
        printf("\nSocketCAN init Timeout %d succeeded\n",timeout.tv_usec);
#endif

// LINUX
        struct sockaddr_can addr;

        memset(&addr, 0, sizeof(addr));
        addr.can_family = AF_CAN;
        addr.can_ifindex = ifr.ifr_ifindex;


        if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
            perror("Socket CAN2 bind");
            return STATUS_BIND_ERROR;
        }

        printf("SocketCAN  bind() succeeded\n");

        int error = 0;
        socklen_t len = sizeof (error);
        int retval = getsockopt (s, SOL_SOCKET, SO_ERROR, &error, &len);
        if (retval != 0) {
            /* there was a problem getting the error code */
            printf("Error getting socket error code: %s\n", strerror(retval));
            perror("Setting timeout failed");
            return STATUS_SOCKET_CREATE_ERROR;
        }
        printf("SocketCAN  getsockopt() succeeded\n");

        if (error != 0) {
           /* socket has a non zero error status */
        	printf("Socket error: %s\n", strerror(error));
            return STATUS_SOCKET_CREATE_ERROR;
        }
        printf("SocketCAN  error none\n");
        sprintf(buf,"%s \n", ifr.ifr_name);
        printf("SocketCAN for interface %s succeeded\n",buf);

        return STATUS_OK;

Hey @vibnwis,

I don't see any read() in your code, can you provide a complete program that I can compile that demonstrates your problem?

Sorry, I just uploaded to https://github.com/vibnwis/socketcan-cpp. After sending out the previous message, I tested it actually worked by itself, ie socketcan-cpp. However, the integrated socketcan-cpp is not. The integrated source is available at https://github.com/vibnwis/Micro-XRCE-DDS-Agent. I am implementing CAN transport onto the Micro-XRCE-DDS-Agent.
CAN2AgentLinux.hpp (include/uxr/agent/transport/can/) defines SocketCan socket_can_;
socketcan_cpp.hpp(include/uxr/agent/transport/can/)
CAN2AgentLinux.cpp (src/uxr/agent/transport/can/)
socketcan_cpp.cpp(src/uxr/agent/transport/can/)

I have checked the SocketCan socket_can_, and s (socket). They don't look abnormal to me.

Very appreciate your comments.

Ok, how to reproduce the issue?

You have a classical NULL pointer deference in your code:

It already fails on the 1st reception of a CAN message:

#0  0x00007ffff7d753a2 in eprosima::uxr::InputMessage::get_buf (this=0x0) at /tmp/Micro-XRCE-DDS-Agent/include/uxr/agent/message/InputMessage.hpp:44
No locals.
#1  0x00007ffff7d74e87 in eprosima::uxr::CAN2Agent::recv_message (this=0x7ffff0001020, input_packet=..., timeout=1, transport_rc=@0x7ffff4df1d9f: eprosima::uxr::TransportRc::ok) at /tmp/Micro-XRCE-DDS-Agent/src/cpp/transport/can/CAN2AgentLinux.cpp:154
        rv = true
        can_status = eprosima::uxr::STATUS_CAN_OP_ERROR
        can_msg = {id = 291, len = 8 '\b', flags = 0 '\000', data = "\021\"3DUfw\210", '\000' <repeats 55 times>}
        i = 8
        __FUNCTION__ = "recv_message"
#2  0x00007ffff7d612cf in eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop (this=0x7ffff0001020) at /tmp/Micro-XRCE-DDS-Agent/src/cpp/transport/Server.cpp:182
        transport_rc = eprosima::uxr::TransportRc::ok
        input_packet = {source = {<eprosima::uxr::EndPoint> = {_vptr.EndPoint = 0x7ffff7f93038 <vtable for eprosima::uxr::CAN2EndPoint+16>}, id_ = 291, len_ = 8 '\b', buf_ = "\021\"3DUfw\210"}, message = std::unique_ptr<eprosima::uxr::InputMessage> = {
            get() = 0x0}}
#3  0x00007ffff7d744d1 in std::__invoke_impl<void, void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> (
    __f=@0x7ffff0012ce0: (void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint> * const)) 0x7ffff7d61238 <eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop()>, 
    __t=@0x7ffff0012cd8: 0x7ffff0001020) at /usr/include/c++/10/bits/invoke.h:73
No locals.
#4  0x00007ffff7d741e5 in std::__invoke<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> (
    __fn=@0x7ffff0012ce0: (void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint> * const)) 0x7ffff7d61238 <eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop()>)
    at /usr/include/c++/10/bits/invoke.h:95
No locals.
#5  0x00007ffff7d73fa5 in std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::_M_invoke<0ul, 1ul> (this=0x7ffff0012cd8) at /usr/include/c++/10/thread:264
No locals.
#6  0x00007ffff7d73e80 in std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::operator() (this=0x7ffff0012cd8) at /usr/include/c++/10/thread:271
No locals.
#7  0x00007ffff7d73e10 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> > >::_M_run (this=0x7ffff0012cd0)
    at /usr/include/c++/10/thread:215
No locals.
#8  0x00007ffff765eed0 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
No symbol table info available.
#9  0x00007ffff6321ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
        ret = <optimized out>
        pd = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {140737301653248, -7587710509487403314, 140737318434334, 140737318434335, 140737301651328, 8396800, 7587686587618643662, 7587691372230692558}, mask_was_saved = 0}}, priv = {pad = {0x0, 0x0, 0x0, 0x0}, 
            data = {prev = 0x0, cleanup = 0x0, canceltype = 0}}}
        not_first_call = 0
#10 0x00007ffff74c8d8f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
No locals.
#0  0x00007ffff7d753a2 in eprosima::uxr::InputMessage::get_buf (this=0x0) at /tmp/Micro-XRCE-DDS-Agent/include/uxr/agent/message/InputMessage.hpp:44
No locals.
#1  0x00007ffff7d74e87 in eprosima::uxr::CAN2Agent::recv_message (this=0x7ffff0001020, input_packet=..., timeout=1, transport_rc=@0x7ffff4df1d9f: eprosima::uxr::TransportRc::ok) at /tmp/Micro-XRCE-DDS-Agent/src/cpp/transport/can/CAN2AgentLinux.cpp:154
        rv = true
        can_status = eprosima::uxr::STATUS_CAN_OP_ERROR
        can_msg = {id = 291, len = 8 '\b', flags = 0 '\000', data = "\021\"3DUfw\210", '\000' <repeats 55 times>}
        i = 8
        __FUNCTION__ = "recv_message"
#2  0x00007ffff7d612cf in eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop (this=0x7ffff0001020) at /tmp/Micro-XRCE-DDS-Agent/src/cpp/transport/Server.cpp:182
        transport_rc = eprosima::uxr::TransportRc::ok
        input_packet = {source = {<eprosima::uxr::EndPoint> = {_vptr.EndPoint = 0x7ffff7f93038 <vtable for eprosima::uxr::CAN2EndPoint+16>}, id_ = 291, len_ = 8 '\b', buf_ = "\021\"3DUfw\210"}, message = std::unique_ptr<eprosima::uxr::InputMessage> = {
            get() = 0x0}}
#3  0x00007ffff7d744d1 in std::__invoke_impl<void, void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> (
    __f=@0x7ffff0012ce0: (void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint> * const)) 0x7ffff7d61238 <eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop()>, 
    __t=@0x7ffff0012cd8: 0x7ffff0001020) at /usr/include/c++/10/bits/invoke.h:73
No locals.
#4  0x00007ffff7d741e5 in std::__invoke<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> (
    __fn=@0x7ffff0012ce0: (void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint> * const)) 0x7ffff7d61238 <eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop()>)
    at /usr/include/c++/10/bits/invoke.h:95
No locals.
#5  0x00007ffff7d73fa5 in std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::_M_invoke<0ul, 1ul> (this=0x7ffff0012cd8) at /usr/include/c++/10/thread:264
No locals.
#6  0x00007ffff7d73e80 in std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::operator() (this=0x7ffff0012cd8) at /usr/include/c++/10/thread:271
No locals.
#7  0x00007ffff7d73e10 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> > >::_M_run (this=0x7ffff0012cd0)
    at /usr/include/c++/10/thread:215
No locals.
#8  0x00007ffff765eed0 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
No symbol table info available.
#9  0x00007ffff6321ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
        ret = <optimized out>
        pd = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {140737301653248, -294153591561088516, 140737318434334, 140737318434335, 140737301651328, 8396800, 294173665125765628, 294168536950149628}, mask_was_saved = 0}}, priv = {pad = {0x0, 0x0, 0x0, 0x0}, 
            data = {prev = 0x0, cleanup = 0x0, canceltype = 0}}}
        not_first_call = 0
#10 0x00007ffff74c8d8f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
==1249481== Thread 4:
==1249481== Conditional jump or move depends on uninitialised value(s)
==1249481==    at 0x483BC98: strlen (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1249481==    by 0x52ECF0D: __vfprintf_internal (vfprintf-internal.c:1688)
==1249481==    by 0x52F806F: __vsprintf_internal (iovsprintf.c:96)
==1249481==    by 0x52D7EB3: sprintf (sprintf.c:30)
==1249481==    by 0x4E3C7A4: eprosima::uxr::SocketCan::read(eprosima::uxr::CanFrame&) (socketcan_cpp.cpp:237)
==1249481==    by 0x4E39BF1: eprosima::uxr::CAN2Agent::recv_message(eprosima::uxr::InputPacket<eprosima::uxr::CAN2EndPoint>&, int, eprosima::uxr::TransportRc&) (CAN2AgentLinux.cpp:135)
==1249481==    by 0x4E262CE: eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop() (Server.cpp:182)
==1249481==    by 0x4E394D0: void std::__invoke_impl<void, void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>(std::__invoke_memfun_deref, void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*&&)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*&&) (invoke.h:73)
==1249481==    by 0x4E391E4: std::__invoke_result<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>::type std::__invoke<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>(void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*&&)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*&&) (invoke.h:95)
==1249481==    by 0x4E38FA4: void std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) (thread:264)
==1249481==    by 0x4E38E7F: std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::operator()() (thread:271)
==1249481==    by 0x4E38E0F: std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> > >::_M_run() (thread:215)
==1249481== 
SocketCAN: Read() "3DUfw 
 
len 8 byte, id: 291 data[0]: 11 data[1]: 22 data[2]: 33 data[3]: 44 data[4]: 55 data[5]: 66 data[6]: 77 data[7]: 88 
==1249481== Invalid read of size 8
==1249481==    at 0x4E3A3A2: eprosima::uxr::InputMessage::get_buf() const (InputMessage.hpp:44)
==1249481==    by 0x4E39E86: eprosima::uxr::CAN2Agent::recv_message(eprosima::uxr::InputPacket<eprosima::uxr::CAN2EndPoint>&, int, eprosima::uxr::TransportRc&) (CAN2AgentLinux.cpp:154)
==1249481==    by 0x4E262CE: eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop() (Server.cpp:182)
==1249481==    by 0x4E394D0: void std::__invoke_impl<void, void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>(std::__invoke_memfun_deref, void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*&&)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*&&) (invoke.h:73)
==1249481==    by 0x4E391E4: std::__invoke_result<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>::type std::__invoke<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>(void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*&&)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*&&) (invoke.h:95)
==1249481==    by 0x4E38FA4: void std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) (thread:264)
==1249481==    by 0x4E38E7F: std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::operator()() (thread:271)
==1249481==    by 0x4E38E0F: std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> > >::_M_run() (thread:215)
==1249481==    by 0x5182ECF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28)
==1249481==    by 0x64E0EA6: start_thread (pthread_create.c:477)
==1249481==    by 0x537ED8E: clone (clone.S:95)
==1249481==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==1249481== 
==1249481== 
==1249481== Process terminating with default action of signal 11 (SIGSEGV)
==1249481==  Access not within mapped region at address 0x0
==1249481==    at 0x4E3A3A2: eprosima::uxr::InputMessage::get_buf() const (InputMessage.hpp:44)
==1249481==    by 0x4E39E86: eprosima::uxr::CAN2Agent::recv_message(eprosima::uxr::InputPacket<eprosima::uxr::CAN2EndPoint>&, int, eprosima::uxr::TransportRc&) (CAN2AgentLinux.cpp:154)
==1249481==    by 0x4E262CE: eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::receiver_loop() (Server.cpp:182)
==1249481==    by 0x4E394D0: void std::__invoke_impl<void, void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>(std::__invoke_memfun_deref, void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*&&)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*&&) (invoke.h:73)
==1249481==    by 0x4E391E4: std::__invoke_result<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>::type std::__invoke<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*>(void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*&&)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*&&) (invoke.h:95)
==1249481==    by 0x4E38FA4: void std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) (thread:264)
==1249481==    by 0x4E38E7F: std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> >::operator()() (thread:271)
==1249481==    by 0x4E38E0F: std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>::*)(), eprosima::uxr::Server<eprosima::uxr::CAN2EndPoint>*> > >::_M_run() (thread:215)
==1249481==    by 0x5182ECF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28)
==1249481==    by 0x64E0EA6: start_thread (pthread_create.c:477)
==1249481==    by 0x537ED8E: clone (clone.S:95)

I suggest to learn how to use gdb, a debugger. It's a tool to figure out what's going on in your program. This is a typical mistake in C or C++ programs, you're dereferencing a pointer that is NULL. As this is not a CAN related problem, I'm going to close this issue.

Happy hacking.

Segmentation fault (core dumped)

Just a hint:
I would assume that you pass a wrong pointer to SocketCan::read when you call it the second time.
Maybe you create a buffer, let it fill by SocketCan::read the first time, print the data, free the original buffer? - and then call SocketCan::read a second time with no valid pointer.

At least it looks like such a situation ...

It already fails on the 1st receive, the pointer to eprosima::uxr::InputMessage::get_buf is NULL.

But from the first read we can see the data and the CAN ID 291 in the log above. How can we see this content then?

I have no idea. Not my turf ¯\_(ツ)_/¯

it is multi-threaded system. the reading is one of the threads; scheduler is another thread, and the other thread experienced null pointer when processing the input packet that came from the reading routine. since they parallel, so we see it entered the reading routine, but failed caused by the other thread. does it make sense.