In Linux, when a target program binds a socket that is already bound, the OS should return an error code indicating that the address is already in use and the target program should proceed, but in Qiling an uncaught except is raised and execution is stopped, which is unexpected and undesired behavior.
Sample Code
Target Program Source Code: (adapted from man bind)
[x] Syscall ERROR: ql_syscall_bind DEBUG: [Errno 98] Address already in use
Traceback (most recent call last):
File "/env/lib/python3.11/site-packages/qiling/os/posix/posix.py", line 374, in load_syscall
retval = syscall_hook(self.ql, *params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/env/lib/python3.11/site-packages/qiling/os/posix/syscall/socket.py", line 433, in ql_syscall_bind
sock.bind(dest)
File "/env/lib/python3.11/site-packages/qiling/os/posix/filestruct.py", line 83, in bind
return self.__socket.bind(address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 98] Address already in use
Expected behavior
Qiling should correctly handle the case where the host OS returns an "Address already in use" error and return the proper return value to the target program. Many programs use the behavior like in test.c to check for already running instances of the program.
Hi @carter-yagemann,
A fix has been committed to dev branch. I am tentatively closing the issue now.
Feel free to check out the updated code and re-open this issue if the problem persists.
Describe the bug
In Linux, when a target program binds a socket that is already bound, the OS should return an error code indicating that the address is already in use and the target program should proceed, but in Qiling an uncaught except is raised and execution is stopped, which is unexpected and undesired behavior.
Sample Code
Target Program Source Code: (adapted from
man bind
)Real Execution:
Qiling Emulation:
Expected behavior Qiling should correctly handle the case where the host OS returns an "Address already in use" error and return the proper return value to the target program. Many programs use the behavior like in
test.c
to check for already running instances of the program.Screenshots N/A
Additional context N/A