Skip to content

XRT-3852: sync with upstream - #4

Merged
SteveOss merged 212 commits into
masterfrom
XRT-3852-branch
Aug 10, 2026
Merged

SteveOss merged 212 commits into
masterfrom
XRT-3852-branch

Conversation

@edward-scott

Copy link
Copy Markdown

No description provided.

stephane and others added 30 commits April 5, 2020 23:09
When compiling with gcc and option -Wconversion it fixes the
warning message

  warning: conversion from ‘X’ {aka ‘x’} to ‘Y’ {aka ‘y’} may change value

Signed-off-by: José Bollo <jose.bollo@iot.bzh>
There is a small typo in tests/bandwidth-client.c.

Should read `response` rather than `reponse`.
Add Embox RTOS to the list of supported OSes
)

While handling MODBUS_FC_WRITE_AND_READ_REGISTERS, both address offsets
must be checked, i.e. the read and the write address must be within the
mapping range.

At the moment, only the read address was considered, it looks like a
simple copy and paste error, so let's fix it.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Sorry for the two PRs, I did one then realized I should check the other
This native libmodbus error code is defined but not used.
stephane and others added 26 commits July 1, 2026 21:58
The setter stored the caller-supplied set_rts callback without a NULL
check; _modbus_rtu_send() then called it unconditionally when RTS mode is
enabled, crashing on a NULL function pointer. Project Vanessa L017 (CWE-476).

Reported-by: Aaron (NVIDIA)
The post-send delay was computed as onebyte_time * req_length +
rts_delay in int arithmetic. onebyte_time grows as the baud rate
shrinks, so a very low baud and a large request overflowed the signed
multiplication (undefined behaviour, reported by UBSan) before the
usleep() argument was formed. Compute the delay in uint64_t and clamp it
to a sane maximum. Project Vanessa L018 (CWE-190).

Reported-by: Aaron (NVIDIA)
_modbus_rtu_ioctl_rts() ignored the return of TIOCMGET/TIOCMSET, so the
library proceeded as if the RTS line had toggled even when the driver
rejected the operation -- a bus-direction/availability hazard on RS-485.
Check both ioctl calls and bail out (with a debug message) on failure.
Project Vanessa L019 (CWE-252).

Reported-by: Aaron (NVIDIA)
The connect path saved the current terminal settings (tcgetattr /
ioctl TCGETS2) without checking the result, then applied new settings.
If the save failed but the apply succeeded, a later close would restore
stale state, leaving the device misconfigured. Abort the connect with a
debug message on save failure. Project Vanessa L015 (CWE-252).

Reported-by: Aaron (NVIDIA)
RTU close ignored failures of the termios restore (tcsetattr /
ioctl TCSETS2), silently leaving the serial device in libmodbus's
modified state. Log the failure (in debug mode) before closing the fd.
Project Vanessa L016 (CWE-252).

Reported-by: Aaron (NVIDIA)
The baud validation rejected 0 but accepted negative values, which
propagated into the stored RTU config, the onebyte_time computation
(division by baud) and the termios speed setup. Reject baud <= 0.
Project Vanessa L030 (CWE-20).

Reported-by: Aaron (NVIDIA)
In the TCP-PI connect path, freeaddrinfo(ai_list) was called after a
getaddrinfo() failure, where ai_list may still be NULL. Some libc
implementations do not treat freeaddrinfo(NULL) as a no-op. Guard the
call with a non-NULL check, matching the listen path. Project Vanessa
L014 (CWE-476).

Reported-by: Aaron (NVIDIA)
The benchmark server inserted the listen socket and every accepted client
socket into a stack fd_set with FD_SET and no FD_SETSIZE check. With
enough open descriptors, accept() returns a descriptor >= FD_SETSIZE and
FD_SET then writes out of bounds of the fd_set (stack corruption).
Refuse/close descriptors >= FD_SETSIZE before FD_SET. A real server
should use poll()/epoll(). Project Vanessa L021/L022 (CWE-787).

Reported-by: Aaron (NVIDIA)
Work on a local descriptor and only assign ctx->s on success:
- PI connect no longer returns success on a stale descriptor when all
  getaddrinfo targets fail
- reconnecting no longer leaks the previously open socket
Initialize w_ser.fd to INVALID_HANDLE_VALUE, guard close against a
never-opened handle and reset it after close to avoid double close of
a reused handle value
Match the POSIX branches which already save/restore errno around
modbus_close/modbus_connect/modbus_flush
Out-of-range values were silently truncated into uint8_t fields and
could overflow the onebyte_time computation
POSIX allows usleep() to fail with EINVAL for values >= 1 second,
skipping the whole post-send delay at very low baud rates
…ntly

The assert(nb_bits < 8) inside the nb_bits > 8 branch aborted debug
builds while release builds silently clamped
The backend request deliberately uses tid 0, matched by the
confirmation pre-check; sft.t_id only restores the frontend tid
The fall-through called modbus_reply with rc == -1 on a stale query,
which failed and broke the loop, contrary to the comment intent
n_loop * nb_points * 1000 overflows int in TCP mode; compute rates in
uint64_t and count the remainder byte per loop iteration
@edward-scott
edward-scott requested a review from SteveOss August 9, 2026 16:31

@SteveOss SteveOss left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Too mant changes to really review. Lets kick this through an test extensively.

@SteveOss
SteveOss merged commit e468cd5 into master Aug 10, 2026
1 check failed
@SteveOss
SteveOss deleted the XRT-3852-branch branch August 10, 2026 10:17
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.