Are you running your server program as root? Does it work when you do so?
Does the code have sufficient error handling?
On UNIX or Linux, port numbers below 1024 are privileged ports that can only be bound with root privileges.
A function that tries to bind the port might return an error code. If your code ignores the error and continues, undefined behavior like buffer overflow may occur.
17.04.2024 18:17:52 Emrah Ali PEKDEMİR <
shaman...@gmail.com>:
> OS: Ubuntu 22.04
> libmodbus 3.1.10
>
> On Wednesday, April 17, 2024 at 7:13:21 PM UTC+3 Emrah Ali PEKDEMİR wrote:
>> My Modbus Server program crashes with **** buffer overflow detected ***: terminated Aborted (core dumped)* , if I want to use 502 as the server port.
>>
>> I tried both server examples coming with the library, and they both crash with any port number less than *1024*. I believe there is a memory leak somewhere, since the crash happens when the program hits rc = modbus_receive(ctx, query).
If the function that initializes the modbus context ctx returns an error, ctx might be uninitialized leading to an error or undefined behavior.
What is the value of rc? If modbus_receive indicates an error, the variable query might be uninitialized.