Commit Graph
1295 Commits
Author SHA1 Message Date
Oliver Hartkopp 1a90b9a75d j1939acd: check length and address of Commanded Address messages
The Commanded Address message contains the 8 byte NAME and the new
source address. The received length was not checked, so the new source
address was taken from stale or uninitialized content of the receive
buffer for short messages. Also the idle and global addresses were
passed to claim_address() which terminates the daemon when bind() fails.

Check for the complete message length and only accept unicast addresses.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 10:21:56 +00:00
Oliver Hartkopp 13dc8e9cc5 isobusfs: srv: check name length against the received message length
The Change Current Directory and Volume Status requests used the path
and volume name length from the request without checking it against
the received message length. Short messages with a big name length made
the server process stale content of the receive buffer as path or
volume name.

Check the name length against the message length, use le16toh() for the
CCD name length and fix the debug output of the volume name.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 10:21:56 +00:00
Oliver Hartkopp d5571a5bc3 isobusfs: srv: pad short Read File responses within the allocated buffer
The Read File response buffer was allocated for the response header and
the requested data only. Short responses (e.g. count = 0) are extended to
ISOBUSFS_MIN_TRANSFER_LENGH which read beyond the allocated buffer and
sent heap content to the client.

Allocate at least ISOBUSFS_MIN_TRANSFER_LENGH bytes and fill the unused
bytes with 0xff.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 10:21:56 +00:00
Oliver Hartkopp 33f7ddb5ed isobusfs: srv: check handle state and owner for read and seek requests
Read File and Seek File requests only checked the handle index to be
within the handles array. Unused or closed handle slots are zeroed
(fd = 0, dir = NULL), so a read request on such a handle read from the
server's stdin and sent the content to the client. Additionally every
client was able to read and seek handles opened by other clients.

Add isobusfs_srv_get_client_handle() which only returns handles that
are in use and have been opened by the requesting client.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 10:21:56 +00:00
Oleksij RempelandOliver Hartkopp c7a02c0258 isobusfs: fix directory read and seek semantics to match ISO 11783-13
Fix directory operations to comply with ISO 11783-13:2021 (sections
C.3.4.2 and C.3.5.2), which specifies that directory operations differ
significantly from standard file operations:
- The Count parameter in a Read File request represents the number of
  directory entries to read, not the number of bytes.
- The Offset parameter in a Seek File request represents the logical
  entry index, not a byte offset.

The previous implementation treated directories strictly as files,
using byte-based offsets and counts. This resulted in incorrect seeking
behavior and protocol violations when listing directories.

Align the implementation with the standard by:

1. Server side:
   - Introduce isobusfs_srv_dir_entry_visible() to consistently
     filter out invalid (unreadable, hidden, oversized) entries. This
     ensures that entry indices remain stable.
   - Implement isobusfs_srv_dir_skip_entries() to advance the
     directory stream by logical visible entries rather than bytes.
   - Update the Read File handler to interpret count as the
     maximum number of entries and return the number of entries read
     in the response header.
   - Update the Seek File handler to seek by entry index.

2. Client side:
   - Calculate the request count based on the number of minimal-size
     entries that fit into the maximum data length.
   - Interpret the response count as the number of entries received
     rather than the byte length of the payload.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
2026-10-14 10:21:56 +00:00
Oleksij RempelandOliver Hartkopp a63fd488b2 isobusfs: treat interactive exit as control flow, not error
The cmd_exit() function used -EINTR to signal a clean exit from the
interactive mode. This is semantically incorrect because EINTR is an
errno value meant for system call interruptions, not application-level
control flow.

Stop using -EINTR for cmd_exit(). Introduce ISOBUSFS_CLI_RET_EXIT (a
positive return code) to distinguish control flow from actual errors.
Map this to exit code 0 in main(), keeping negative errno values for
real errors. This makes the exit path explicit and prevents confusion
with actual interrupted system calls.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
2026-10-14 10:21:55 +00:00
Oleksij RempelandOliver Hartkopp 64280dc9c3 isobusfs: selftest: Handle read requests larger than file size
Add expected_size field to test patterns to properly validate cases
where the requested read size exceeds the actual file size. This allows
testing the server's behavior when clients request more data than is
available.

When a read request is larger than the file, the server correctly
returns data up to EOF. The test framework now distinguishes between
this expected scenario and genuine read failures.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
[socketcan: addressed review comments from PR #629:
 - keep uint32_t instead of size_t for offset/read_size/expected_size:
   ISO 11783-13 limits the file offset (Seek File) and the file size
   (directory entry) to 32 bit, so uint32_t matches the protocol. The
   sum offset + read_size can exceed 32 bit (see UINT32_MAX pattern)
   and is therefore calculated in int64_t. size_t would not help here
   as it is only 32 bit wide on 32 bit targets.
 - remaining_size is a signed int64_t: the signed type is needed to
   detect the 'remaining_size < 0' case (server returned more data than
   requested) and int64_t holds the 33 bit sum on all platforms.
 - fix printf format for the uint32_t read_offset (%zu -> %u)]
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 10:21:55 +00:00
Oliver Hartkopp 1663fc32b3 slcanpty: use the SLCAN message length when parsing commands
pty2can() detected complete SLCAN messages by looking for the '\r'
termination but did not use this message length for parsing. The
content was read at fixed positions and the start of the following
message was derived from the parsed content.

Too short messages (e.g. 'T1\r') read the DLC and data from stale
buffer content and sent a phantom CAN frame. Following commands got
lost after short messages, unknown commands or frames with timestamp.

Terminate the current message at its '\r' position, check that the
CAN ID fits into the message and always continue with the next message
behind the '\r'.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 11:15:54 +02:00
Oliver Hartkopp 38cf8dd1a5 cangw: fix NULL pointer dereference in modification parsing
parse_mod() and parse_fdmod() did not check the return value of
strchr() when looking for the ':' delimiters. A modification definition
without ':' (e.g. '-m AND') led to a segmentation fault.

Add the missing NULL pointer checks.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 11:15:54 +02:00
Oliver Hartkopp 411a68675f lib: snprintf_can_error_frame: document and check required buffer size
The helper functions for the error frame content added the return
values of snprintf() to the buffer offset without checking for
truncation. With a too small buffer the following 'len - n' calculation
wrapped around (size_t) and subsequent snprintf() calls could write
beyond the end of the buffer.

As the maximum output length is known, introduce CANERR_BUFFSZ in lib.h
with a description how the required buffer size is calculated and
return an empty string if the provided buffer is smaller. The only user
candump provides a buffer of more than 6000 bytes for this function.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 11:15:54 +02:00
Oliver Hartkopp 6bdb574707 asc2log: use unsigned types for DLC and data length values
The DLC and data length values were read into signed integers with
%x and %d. Negative values (e.g. '-1' or 'ffffffff') passed the range
checks and led to len values of 255 or 65535. Via the union cfu
these classic CAN frames were then printed as CAN XL frames.

Use unsigned int for dlc/dlen and %u for the data length so that
negative values are caught by the existing range checks.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 11:15:54 +02:00
Oliver Hartkopp fa647cc3e2 asc2log: do not read beyond the end of line when parsing hex data
The data parsing loops in the CANFD/CANXL evaluation functions jumped
three characters forward after each hex byte without checking the
separator. When a line ended directly after a hex byte (e.g. last line
without newline or a line split by fgets()) the pointer skipped the
string termination and continued parsing stale content from previous
lines - or in the worst case read beyond the input buffer.

Factor out the four identical loops into get_hex_data() which requires
a whitespace separator behind each hex byte.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-10-14 11:15:54 +02:00
Oliver Hartkopp cbbad5eede lib: parse_canframe: guard delimiter reads with length checks
As Alex J pointed out in comment
https://github.com/linux-can/can-utils/issues/632#issuecomment-5746692502
the delimiters to detect CAN CC/FD/XL frames were read from the input
data without checking the length of that input data. This could lead
to an out-of-bounds read and to unintended detection of incorrect content.

Add a length check before reading those delimiters and also add/change
some comments to clarify the reasons for some assignments.

Reported-by: Alex J <jipaionut@gmail.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2026-09-20 21:44:32 +02:00
Oleksij RempelandGitHub 95aae6bf83 Merge pull request #626 from SamantazFox/patch-1
J1939: VP1/VP2 PG fixes
2026-05-12 15:48:35 +02:00
Oleksij RempelandOliver Hartkopp bf5fe736c3 canlogserver: fix infinite loops during signal handling
Fix infinite loops that prevent graceful termination when the server
receives SIGINT or SIGTERM signals. Without this fix, Ctrl-C and kill
commands are ignored, making it impossible to stop the server cleanly.

Two scenarios cause the infinite loops:

1) The bind() retry loop: When the port is busy, the loop retries
   indefinitely without checking the running flag set by the signal
   handler.

2) The accept() loop: The loop is unconditional, so when accept() is
   interrupted by a signal and returns EINTR, the loop immediately
   restarts, ignoring the shutdown request.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
2026-05-12 10:22:48 +02:00
Marc Kleine-BuddeandGitHub 14245b7c79 Merge pull request #627 from SamantazFox/patch-2
J1939: Handle localtime_r() failure in TD PG
2026-05-11 10:16:48 +02:00
Samantaz Fox 90383a0cca Fill unassigned bytes with 0xFF in J1939 VP2 2026-05-08 17:18:03 +02:00
Samantaz Fox d5cb91c8ea Handle localtime_r() failure in j1939 timedate
When the call to localtime_r() fails (by returning NULL, as per the POSIX specification), make sure to fill the hour/minute offsets with the fallback values as specified in the J1939DA supporting information.
2026-05-08 17:00:31 +02:00
Samantaz FoxandGitHub 9743a2ffcf Add j1939 VP2 details
Add 3 missing unused bytes (for a message len of 8) to the j1939 VP2 struct, as well as range information for the existing parameters.
2026-05-05 20:56:39 +00:00
Samantaz FoxandGitHub d5ed23583c Update j1939 VP1 parameters ranges
Lat/longitude parameters have a range of -210 to +211.1081215
2026-05-05 20:48:33 +00:00
Samantaz FoxandGitHub 60301896d1 Update j1939 VP1 repetition rate
Since J1939DA:SEP2015, the repetition rate of VP1 has been changed to 1s.
2026-05-05 20:44:47 +00:00
Marc Kleine-BuddeandGitHub 99ab67143a Merge pull request #625 from marckleinebudde/bcmserver-fix-buffer-overflow
bcmserver: fix buffer overflow
2026-03-10 10:58:56 +01:00
Marc Kleine-Budde a0aeaed234 bcmserver: main(): rxmsg: increase buffer size to hold long network interface names
Message-ID: <DM6PR17MB28748DA25E52E1BD3EC593E6937AA@DM6PR17MB2874.namprd17.prod.outlook.com>
2026-03-10 10:46:12 +01:00
Marc Kleine-Budde 3cae8a449b bcmserver: main(): convert from sprintf() to snprintf() to avoid buffer overflow
Message-ID: <DM6PR17MB28748DA25E52E1BD3EC593E6937AA@DM6PR17MB2874.namprd17.prod.outlook.com>
2026-03-10 10:46:11 +01:00
Marc Kleine-BuddeandGitHub 44e6eb45e3 Merge pull request #624 from marckleinebudde/canerrsim-fix-buffer-overflow
canerrsim: main(): avoid buffer overflow: check length of interface name
2026-03-09 12:27:28 +01:00
Marc Kleine-Budde 9e444073b1 canerrsim: main(): avoid buffer overflow: check length of interface name
Closes: https://github.com/linux-can/can-utils/issues/623
2026-03-09 12:23:29 +01:00
Marc Kleine-Budde 9d4f3c82a2 canerrsim: add missing \n at end of error messages 2026-03-09 12:21:33 +01:00
Marc Kleine-Budde 7e8e247b2f canerrsim: convert from show_custom_format_and_exit() to err_exit() 2026-03-09 12:20:50 +01:00
Marc Kleine-Budde 3fe1c42bbf canerrsim: err_exit(): add support for printf style formats 2026-03-09 12:18:10 +01:00
Marc Kleine-BuddeandGitHub 1520ab5b98 Merge pull request #620 from marckleinebudde/mcp251xfd-fix-strchr
mcp251xfd: mcp251xfd_regmap_read(): don't assign return value of `strchr()` to `char *`
2026-03-04 11:38:43 +01:00
Marc Kleine-Budde aa902ae2af mcp251xfd: mcp251xfd_regmap_read(): don't assign return value of strchr() to char *
The `file_path` of `strchr(file_path, '/')` is a `const char *`. In this
case the `strchr()` in debian experimental returns a `const char *`,
leading to this error message:

```
mcp251xfd/mcp251xfd-regmap.c:75:13: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
   75 |         tmp = strchr(file_path, '/');
      |             ^
```

Fix the error by using the return value from `strchr()` directly in the
`if()`.

Link: https://github.com/linux-can/can-utils/actions/runs/22649777324/job/65679726209?pr=619
2026-03-04 11:35:38 +01:00
Marc Kleine-BuddeandGitHub a0b592178e Merge pull request #621 from marckleinebudde/remove-mips
github-actions: remove mips for now

Closes: https://github.com/linux-can/can-utils/issues/611
2026-03-04 11:34:12 +01:00
Marc Kleine-Budde 4f2fdecfba github-actions: remove mips for now
It's being phased out on Ubuntu rolling release.
2026-03-04 11:30:14 +01:00
Marc Kleine-BuddeandGitHub cbbe4b41ea Merge pull request #616 from pastalian/cmake-compat
cmake: set policy version to 3.10
2026-01-19 09:49:51 +01:00
Takuya Wakazono 2da0c7e95e cmake: set policy version to 3.10
This project does not rely on any behavior from CMake <3.10, and
compatibility with CMake <3.10 is expected to be removed in future
releases.

https://cmake.org/cmake/help/v4.0/manual/cmake-policies.7.html#policies-introduced-by-cmake-3-10

```
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.
```
2026-01-19 15:37:11 +09:00
Marc Kleine-BuddeandGitHub 1f038b3cd8 Merge pull request #614 from hartkopp/master
canxl extension: use plain union instead of typedef
2025-12-18 19:26:31 +01:00
Oliver Hartkopp 392ccc970b canxl extension: use plain union instead of typedef
"In general, a pointer, or a struct that has elements that can reasonably
be directly accessed should never be a typedef."

https://www.kernel.org/doc/html/v5.0/process/coding-style.html#typedefs

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-12-18 18:23:38 +01:00
Oliver Hartkopp 7939678070 can-utils: unify indention
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-12-13 10:38:15 +01:00
Marc Kleine-BuddeandGitHub 88a0417a6b Merge pull request #609 from dphipps-qnx/fix_cmsg_types
candump: Use SCM_* consts instead of SO_* for cmsg_type
2025-12-05 16:26:30 +01:00
Darcy Phipps 65e715d56d candump: Use SCM_* consts instead of SO_* for cmsg_type
There are explicit #defines for SCM_TIMESTAMP and SCM_TIMESTAMPING. They
currently happen to have the same value as SO_TIMESTAMP and
SO_TIMESTAMPING but the former should be used when checking cmsg_type in
case one day they do not.
2025-12-05 09:35:50 -05:00
Oliver Hartkopp 374fecde09 cangen: disable generation of unsupported CAN frame types in mixed mode
The mixed mode is able to automatically detect the potential supported
CAN frame types CAN CC/FD/XL by checking the CAN device MTU at startup.

Usually the MTU shows which CAN frame types can be sent but in the case of
CAN XL in CANXL-only mode CC and FD frames can not be sent on the CAN_RAW
socket.

Since this patch [1] the CAN_RAW socket rejects unsupported CAN frames and
returns -EINVAL as error code. With this change in cangen the CC and FD
frame generation can be disabled in mixed mode at runtime.

[1] https://lore.kernel.org/linux-can/20251125123859.3924-17-socketcan@hartkopp.net/T/#u

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-12-03 16:09:12 +01:00
Oliver Hartkopp bfbf0c851f cangen: auto enable FD/XL content in mixed mode
Automatically create FD/XL content in mixed mode when the CAN interface
is capable to deal with it.

Suggested-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-12-03 16:09:12 +01:00
Oliver Hartkopp ed7822c9a2 candump: print CAN XL specific flags as extra message infos
The extra message infos BRS and ESI have been printed when enabled with
the '-x' option. Since CAN XL has similar flags (SEC and RRS) those flags
have been wrongly printed as CAN FD flags.

This patch introduces separate flags for the CAN XL frames and prints them
when a CAN XL frame is processed.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-11-26 19:04:50 +01:00
Marc Kleine-BuddeandGitHub e9ea9d1168 Merge pull request #607 from marckleinebudde/cansend-fix-typo
cansend: fix typo in CANFD_FDF flag name
2025-11-07 12:55:39 +01:00
Marc Kleine-Budde 2d793d38d2 cansend: fix typo in CANFD_FDF flag name
Closes: https://github.com/linux-can/can-utils/issues/606
Fixes: 3e0e6ae3a4 ("cansend: print canfd_frame.flags in help text")
2025-11-07 12:51:19 +01:00
Marc Kleine-BuddeandGitHub 340a3b8c92 Merge pull request #605 from marckleinebudde/lib_h-selfcontained
lib.h: include linux/can.h
2025-11-07 12:34:08 +01:00
Marc Kleine-BuddeandGitHub 8838ce80fc Merge pull request #604 from marckleinebudde/cansend-canfd-flags
cansend: print canfd_frame.flags in help text
2025-11-07 12:33:02 +01:00
Marc Kleine-Budde d6c57240ed lib.h: include linux/can.h
Make lib.h self contained, so that language servers can parse it without
errors.
2025-11-07 12:30:15 +01:00
Marc Kleine-Budde 3e0e6ae3a4 cansend: print canfd_frame.flags in help text 2025-11-07 12:05:04 +01:00
Oliver Hartkopp 8bf5f8873f Fix optional nanosecond timestamp
The extension of the timestamp size is missing in log2asc.c and canplayer.c

Fixes: 987bc8aac2 ("Optional nanosecond timestamp logging")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-09-03 12:55:26 +02:00