XRT-3852: sync with upstream - #4
Merged
Merged
Conversation
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
Thanks to @peternewman
) 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.
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
SteveOss
approved these changes
Aug 10, 2026
SteveOss
left a comment
There was a problem hiding this comment.
Too mant changes to really review. Lets kick this through an test extensively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.