Commit 7ef165d
committed
io/socket: address review of the poll() conversion
Follow-up to the FD_SETSIZE fix, covering the points raised in review.
Negative/overflowing I/O timeouts. set_io_timeout() could produce a negative
select_timeout (a peer-supplied MSG_IO_TIMEOUT value was applied unchecked),
and every wait now passes select_timeout * 1000 to poll(), where a negative
millisecond count means "wait forever" -- so a hostile or buggy peer could
stall the other side and bypass keepalives entirely. select() used to reject
that with EINVAL, which kept the loop and check_timeout() running. Clamp a
negative argument to 0, compute allowed_lull without overflowing near INT_MAX
(secs / 2 + secs % 2), ignore a non-positive MSG_IO_TIMEOUT value, and funnel
all three waits through poll_timeout_ms(), which keeps the count positive and
bounded.
The daemon accept loop had the same fd_set overflow. start_accept_loop() still
stored listening sockets in an fd_set, so a daemon started with enough
descriptors already open got listener fds >= FD_SETSIZE and hit the same
undefined behaviour at startup -- verified: with the old code a transfer
through such a daemon yields nothing, with this change it succeeds. Converted
it to poll() as well.
Readiness testing. Treating any non-zero revents as ordinary readiness was
wrong: poll() reports POLLERR/POLLHUP/POLLNVAL unrequested, and an invalid fd
shows up as POLLNVAL on a successful poll() rather than -1/EBADF, which left
the EBADF branches dead and let an invalid ff_forward_fd reach
forward_filesfrom_data() (where EBADF reads as EOF). Use role-specific masks
(POLL_RD_BITS / POLL_WR_BITS), handle POLLNVAL explicitly in all three loops,
and request POLLPRI so select()'s old exception set is not silently dropped.
A bidirectional fd is no longer entered twice. A direct daemon connection uses
one fd for both directions; it now occupies a single pollfd row with OR-ed
events instead of two rows carrying different masks, which also avoids the
Cygwin < 3.3.6 duplicate-entry readiness bug.
poll() is now a declared requirement: configure.ac checks for poll.h and
poll(), failing with a clear message rather than leaving it implicit.
The test no longer hardcodes FD_SETSIZE (1024 on glibc but 65536 on 64-bit
Solaris, where it would have opened too few fds and passed vacuously); it asks
the C library for the real value via a small compiled probe and skips if that
is unavailable. Its description now also covers the fortified-libc case, where
the pre-fix result is an abort rather than a hang.1 parent 4a751a2 commit 7ef165d
4 files changed
Lines changed: 175 additions & 74 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
909 | 909 | | |
910 | 910 | | |
911 | 911 | | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
912 | 918 | | |
913 | 919 | | |
914 | 920 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
115 | 121 | | |
116 | 122 | | |
117 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
118 | 137 | | |
119 | 138 | | |
120 | 139 | | |
| |||
251 | 270 | | |
252 | 271 | | |
253 | 272 | | |
254 | | - | |
| 273 | + | |
255 | 274 | | |
256 | 275 | | |
257 | | - | |
| 276 | + | |
258 | 277 | | |
259 | | - | |
| 278 | + | |
260 | 279 | | |
261 | 280 | | |
262 | 281 | | |
263 | 282 | | |
264 | 283 | | |
265 | 284 | | |
266 | 285 | | |
267 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
268 | 293 | | |
269 | 294 | | |
270 | 295 | | |
| |||
337 | 362 | | |
338 | 363 | | |
339 | 364 | | |
340 | | - | |
| 365 | + | |
341 | 366 | | |
342 | | - | |
| 367 | + | |
343 | 368 | | |
344 | 369 | | |
345 | 370 | | |
| |||
348 | 373 | | |
349 | 374 | | |
350 | 375 | | |
351 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
352 | 382 | | |
353 | 383 | | |
354 | 384 | | |
| |||
657 | 687 | | |
658 | 688 | | |
659 | 689 | | |
660 | | - | |
| 690 | + | |
661 | 691 | | |
662 | 692 | | |
663 | 693 | | |
| |||
714 | 744 | | |
715 | 745 | | |
716 | 746 | | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
721 | 759 | | |
722 | 760 | | |
723 | 761 | | |
| |||
757 | 795 | | |
758 | 796 | | |
759 | 797 | | |
760 | | - | |
| 798 | + | |
761 | 799 | | |
762 | 800 | | |
763 | | - | |
| 801 | + | |
764 | 802 | | |
765 | 803 | | |
766 | 804 | | |
| |||
784 | 822 | | |
785 | 823 | | |
786 | 824 | | |
787 | | - | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
788 | 839 | | |
789 | 840 | | |
790 | 841 | | |
| |||
833 | 884 | | |
834 | 885 | | |
835 | 886 | | |
836 | | - | |
| 887 | + | |
837 | 888 | | |
838 | 889 | | |
839 | 890 | | |
| |||
894 | 945 | | |
895 | 946 | | |
896 | 947 | | |
897 | | - | |
| 948 | + | |
| 949 | + | |
898 | 950 | | |
899 | 951 | | |
900 | 952 | | |
| |||
1153 | 1205 | | |
1154 | 1206 | | |
1155 | 1207 | | |
| 1208 | + | |
| 1209 | + | |
1156 | 1210 | | |
1157 | | - | |
| 1211 | + | |
| 1212 | + | |
1158 | 1213 | | |
1159 | 1214 | | |
1160 | 1215 | | |
| |||
1559 | 1614 | | |
1560 | 1615 | | |
1561 | 1616 | | |
1562 | | - | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
1563 | 1621 | | |
1564 | 1622 | | |
1565 | 1623 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
536 | 537 | | |
537 | 538 | | |
538 | 539 | | |
539 | | - | |
540 | | - | |
| 540 | + | |
| 541 | + | |
541 | 542 | | |
542 | 543 | | |
543 | 544 | | |
| |||
549 | 550 | | |
550 | 551 | | |
551 | 552 | | |
552 | | - | |
553 | | - | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
554 | 559 | | |
555 | 560 | | |
556 | 561 | | |
| |||
560 | 565 | | |
561 | 566 | | |
562 | 567 | | |
563 | | - | |
564 | | - | |
565 | | - | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
566 | 571 | | |
567 | 572 | | |
568 | 573 | | |
569 | 574 | | |
570 | 575 | | |
571 | | - | |
572 | 576 | | |
573 | 577 | | |
574 | 578 | | |
575 | 579 | | |
576 | 580 | | |
577 | | - | |
| 581 | + | |
578 | 582 | | |
579 | 583 | | |
580 | 584 | | |
581 | 585 | | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
| 586 | + | |
| 587 | + | |
587 | 588 | | |
588 | | - | |
| 589 | + | |
589 | 590 | | |
590 | 591 | | |
591 | | - | |
592 | | - | |
| 592 | + | |
| 593 | + | |
593 | 594 | | |
594 | 595 | | |
595 | 596 | | |
| |||
0 commit comments