Skip to content

canbus: handle socket bind failures - #6

Open
Opriego wants to merge 1 commit into
jeremyhahn:masterfrom
Opriego:fix/canbus-bind-error-check
Open

canbus: handle socket bind failures#6
Opriego wants to merge 1 commit into
jeremyhahn:masterfrom
Opriego:fix/canbus-bind-error-check

Conversation

@Opriego

@Opriego Opriego commented Aug 17, 2026

Copy link
Copy Markdown

Summary

  • add a focused regression test for CAN socket bind failures
  • make canbus_connect return its existing bind error code when bind returns -1

Problem

canbus_connect checks whether bind returns a value less than -1. POSIX
socket errors are reported as -1, so the function ignores a normal bind
failure, continues configuring the socket, marks the client connected, and
returns success.

Fix

Change the bind result check from < -1 to < 0.

Testing

The regression test wraps the socket calls so that socket and ioctl succeed
while bind returns -1. It also verifies that socket options are not applied
after the bind failure.

Before the fix:

0%: Checks: 1, Failures: 1, Errors: 0
canbus_connect(&client) returned 0 instead of 6

After the fix:

100%: Checks: 1, Failures: 0, Errors: 0

The existing canbus_shutdown pointer/integer comparison warning is unrelated
and remains unchanged.

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.

1 participant