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

AP_AIS: remove incorrect use of strncat #29171

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

peterbarker
Copy link
Contributor

the third argument is space remaining in buffer, not size of buffer...

../../libraries/AP_AIS/AP_AIS.cpp:183:71: warning: Potential buffer overflow. Replace with 'sizeof(multi) - strlen(multi) - 1' or use a safer 'strlcat' API [unix.cstring.BadSizeArg]
strncat(multi,_AIVDM_buffer[msg_parts[i]].payload,sizeof(multi));
^~~~~~~~~~~~~
../../libraries/AP_AIS/AP_AIS.cpp:185:49: warning: Potential buffer overflow. Replace with 'sizeof(multi) - strlen(multi) - 1' or use a safer 'strlcat' API [unix.cstring.BadSizeArg]
strncat(multi,_incoming.payload,sizeof(multi));

the third argument is space remaining in buffer, not size of buffer...

../../libraries/AP_AIS/AP_AIS.cpp:183:71: warning: Potential buffer overflow. Replace with 'sizeof(multi) - strlen(multi) - 1' or use a safer 'strlcat' API [unix.cstring.BadSizeArg]
                    strncat(multi,_AIVDM_buffer[msg_parts[i]].payload,sizeof(multi));
                                                                      ^~~~~~~~~~~~~
../../libraries/AP_AIS/AP_AIS.cpp:185:49: warning: Potential buffer overflow. Replace with 'sizeof(multi) - strlen(multi) - 1' or use a safer 'strlcat' API [unix.cstring.BadSizeArg]
                strncat(multi,_incoming.payload,sizeof(multi));
@rmackay9
Copy link
Contributor

Looks like it was a young version of @IamPete1 who wrote the code so I've added him to the reviewers list

Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still works, I have tested with the simulated AIS. Although I don't think there are any multi part messages in the example data...

@IamPete1
Copy link
Member

IamPete1 commented Jan 30, 2025

I suspect this bug was why we weren't getting all sorts of errors with the existing code, we do have multi part messages but it was never trying to reassemble. #29195

I would be un-surprised if there are other bugs hiding in AIS, its quite a complex protocol.

@peterbarker peterbarker merged commit 6bf29ec into ArduPilot:master Jan 31, 2025
100 checks passed
@peterbarker peterbarker deleted the pr/ais-strncat-bugfix branch January 31, 2025 07:13
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

Successfully merging this pull request may close these issues.

3 participants