autowarefoundation / ros2_socketcan

A ROS2 wrapper around Linux SocketCAN
Apache License 2.0
119 stars 58 forks source link

fix previously received data remains #18

Closed a-higuchi closed 2 years ago

a-higuchi commented 2 years ago

Relate https://github.com/autowarefoundation/ros2_socketcan/issues/17

Description

If the DLC(Data Length Code) is less than 8, the previously received data remains in the "data" field of the topic sent by ros2_socketcan.

When supporting multiple types of HW with the same CAN-ID but different DLCs(*see below for further details), unintended behavior may occur if garbage is included in the reception result of can_receiver.

*Description about "CAN-ID but different DLCs". For example, there are two HWs, HW1 and HW2, and the specification of HW1's CAN-ID: 100h is as follows.

CAN-ID DLC data1 data2 data3 data4 data5 data6 data7 data8
100h 1 lamp1 on - - - - - - -

In contrast to the above, if the HW2 CAN-ID: 100h specification is as follows, a malfunction may occur if the previously received data remains in the "data" field.

CAN-ID DLC data1 data2 data3 data4 data5 data6 data7 data8
100h 2 lamp1 on/off lamp2 on/off - - - - - -

Current problem

The data length for memcopy was the DLC value in SocketCanReceiver::receive.
As a result, when receiving data with a DLC length of less than 8, the data after the DLC data length was not initialized, and the previously received data remained in the buffer.

Countermeasures

Fixed data length to memcopy to be the size of the data field.

Review Procedure

I have confirmed that the unused data fields have been initialized by the steps described in the issue.

JWhitleyWork commented 2 years ago

Sorry, I didn't realize I was still a maintiner on this project!

mitsudome-r commented 2 years ago

@JWhitleyWork Thanks for taking a look at this. Since you are no longer an AWF employee, I have removed you from the maintainer for now and assigned others from AWF. If you still wish to continue as a maintainer, please let me know.

JWhitleyWork commented 2 years ago

@mitsudome-r Yes, I would appreciate staying as a maintainer. I'm fine collaborating with the AWF but I'm still actively using and developing this project and am willing to help review PRs.