Commit 7b13341
committed
Fix FD_SET overflow when socket fd >= FD_SETSIZE
When a TCP server accepts a socket with a file descriptor >= FD_SETSIZE
(commonly 1024), the FD_SET macro writes past the end of the fd_set
buffer, causing memory corruption or abort via glibc __fdelt_chk.
An attacker can trigger this by exhausting file descriptors so the next
accepted connection gets a high-numbered fd, then sending any request
to drive modbus_receive().
Guard all FD_SET call sites: reject fds >= FD_SETSIZE early at
accept/connect time, and add defensive checks before each FD_SET use
in _modbus_receive_msg, _connect, _modbus_tcp_select, _modbus_tcp_flush,
and _modbus_rtu_select.
Reported-by: Lukas Dresel <lukas@artiphishell.com>
Reported-by: Fabio <team@artiphishell.com>1 parent b7ee556 commit 7b13341
3 files changed
Lines changed: 77 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1150 | 1150 | | |
1151 | 1151 | | |
1152 | 1152 | | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
1153 | 1157 | | |
1154 | 1158 | | |
1155 | 1159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
300 | 304 | | |
301 | 305 | | |
302 | 306 | | |
| |||
350 | 354 | | |
351 | 355 | | |
352 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
353 | 371 | | |
354 | 372 | | |
355 | 373 | | |
| |||
440 | 458 | | |
441 | 459 | | |
442 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
443 | 473 | | |
444 | 474 | | |
445 | 475 | | |
| |||
501 | 531 | | |
502 | 532 | | |
503 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
504 | 538 | | |
505 | 539 | | |
506 | 540 | | |
| |||
743 | 777 | | |
744 | 778 | | |
745 | 779 | | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
746 | 794 | | |
747 | 795 | | |
748 | 796 | | |
| |||
777 | 825 | | |
778 | 826 | | |
779 | 827 | | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
780 | 842 | | |
781 | 843 | | |
782 | 844 | | |
| |||
800 | 862 | | |
801 | 863 | | |
802 | 864 | | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
803 | 869 | | |
804 | 870 | | |
805 | 871 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
388 | 395 | | |
389 | 396 | | |
390 | 397 | | |
| |||
0 commit comments