Overview
| Artifact ID: | 418dfa50eca41171ec4525f20d27fccf9ac99f37 |
|---|---|
| Ticket: | 4d5ae7d88afc99c9039b66c4e942d45ecdb6f986
crash in [socket] |
| User & Date: | gahr on 2016-09-27 19:50:40 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
I nailed down a crash in test http-3.29 to this commit [bf44d3d17ca27c86]. The test tries to open a connection to the localhost IPv6 address and crashes if the machine does not have an IPv6 interface. The changed logic in [bf44d3d17ca27c86] is that the error variable in TcpConnect() is initialized to the value of errno (happens to be 0) instead of being left uninitialized. This changes the implicit initial state from "there's an error unless proved otherwise" to "there's no error unless proved otherwise". I can reproduce the crash with this script: ================================================================== proc connect {sock} { chan close $sock set ::forever 1 } set sock [socket -async ::1 80] fileevent $sock writable [list connect $sock] vwait forever ================================================================== Backtrace: ================================================================== 0x00000000005c2f00 in Tcl_CreateFileHandler (fd=-1, mask=6, proc=0x5bf960 <WrapNotify>, clientData=0x801ceeb90) at tclUnixNotfy.c:630 630 FD_SET(fd, &tsdPtr->checkMasks.readable); Current language: auto; currently minimal (gdb) bt #0 0x00000000005c2f00 in Tcl_CreateFileHandler (fd=-1, mask=6, proc=0x5bf960 <WrapNotify>, clientData=0x801ceeb90) at tclUnixNotfy.c:630 #1 0x00000000005bf76e in TcpWatchProc (instanceData=0x801ceeb90, mask=4) at tclUnixSock.c:1005 #2 0x0000000000537673 in ChanWatch (chanPtr=0x801cee390, mask=4) at /root/fossil/tcl/generic/tclIO.c:507 #3 0x000000000052bab6 in UpdateInterest (chanPtr=0x801cee390) at /root/fossil/tcl/generic/tclIO.c:8486 #4 0x0000000000533432 in Tcl_CreateChannelHandler (chan=0x801cee390, mask=4, proc=0x533610 <TclChannelEventScriptInvoker>, clientData=0x801cef1d0) at /root/fossil/tcl/generic/tclIO.c:8611 #5 0x0000000000533d62 in CreateScriptRecord (interp=0x801c30010, chanPtr=0x801cee390, mask=4, scriptPtr=0x801ce0c00) at /root/fossil/tcl/generic/tclIO.c:8818 #6 0x0000000000533b48 in Tcl_FileEventObjCmd (clientData=0x0, interp=0x801c30010, objc=4, objv=0x801c632f0) at /root/fossil/tcl/generic/tclIO.c:8978 #7 0x000000000040f8b1 in Dispatch (data=0x801ce0ff8, interp=0x801c30010, result=0) at /root/fossil/tcl/generic/tclBasic.c:4358 #8 0x000000000040b42c in TclNRRunCallbacks (interp=0x801c30010, result=0, rootPtr=0x0) at /root/fossil/tcl/generic/tclBasic.c:4391 #9 0x000000000040b149 in Tcl_EvalObjv (interp=0x801c30010, objc=4, objv=0x801c632f0, flags=2097168) at /root/fossil/tcl/generic/tclBasic.c:4121 #10 0x000000000040cc8d in TclEvalEx (interp=0x801c30010, script=0x801cc7a10 "proc connect {sock} {\n chan close $sock\n set ::forever 1\n}\n\nset sock [socket -async ::1 80]\nfileevent $sock writable [list connect $sock]\nvwait forever\n", numBytes=158, flags=0, line=7, clNextOuter=0x0, outerScript=0x801cc7a10 "proc connect {sock} {\n chan close $sock\n set ::forever 1\n}\n\nset sock [socket -async ::1 80]\nfileevent $sock writable [list connect $sock]\nvwait forever\n") at /root/fossil/tcl/generic/tclBasic.c:5260 #11 0x0000000000548d0a in Tcl_FSEvalFileEx (interp=0x801c30010, pathPtr=0x801c62150, encodingName=0x0) at /root/fossil/tcl/generic/tclIOUtil.c:1826 #12 0x000000000055316c in Tcl_MainEx (argc=-1, argv=0x7fffffffea90, appInitProc=0x404fd0 <Tcl_AppInit>, interp=0x801c30010) at /root/fossil/tcl/generic/tclMain.c:424 #13 0x0000000000404fbf in main (argc=2, argv=0x7fffffffea80) at tclAppInit.c:84 ================================================================== Suggested patch, which solves the problem for me: Index: unix/tclUnixSock.c ================================================================== --- unix/tclUnixSock.c +++ unix/tclUnixSock.c @@ -1096,11 +1096,11 @@ Tcl_Interp *interp, /* For error reporting; can be NULL. */ TcpState *statePtr) { socklen_t optlen; int async_callback = statePtr->flags & TCP_ASYNC_PENDING; - int ret = -1, error = errno; + int ret = -1, error = EHOSTUNREACH; int async = statePtr->flags & TCP_ASYNC_CONNECT; if (async_callback) { goto reenter; } ================================================================== With this patch, the script above behaves as follows, similarly to what it did in Tcl 8.5. ================================================================== couldn't open socket: host is unreachable while executing "socket -async ::1 80" invoked from within "set sock [socket -async ::1 80]" (file "sockcrash.tcl" line 6) ================================================================== The test suite passes, with the patch applied. - foundin changed to: "trunk"
- is_private changed to: "0"
- login: "gahr"
- priority changed to: "5 Medium"
- private_contact changed to: "438e59f1f1c891b29d2528ed82d1e629cecc6336"
- resolution changed to: "None"
- severity changed to: "Severe"
- status changed to: "Open"
- submitter changed to: "gahr"
- subsystem changed to: "25. Channel System"
- title changed to: "crash in [socket]"
- type changed to: "Bug"