<i>Don't call getsockname(2) in Tcl_MakeFileChannel(3) unless absolutely necessary</i>.
by
.
D 2018-06-07T06:25:47.360
J assignee nobody
J closer nobody
J cmimetype text/html
J comment Tcl_MakeFileChannel(3)\schecks\sif\sthe\sgiven\sfd\sis\sa\stty\sor\sa\ssocket\sbefore\sassuming\sit's\sa\sfile.\r\n<br>\r\nIf\sthere\sare\s<a\shref="https://man.openbsd.org/pledge">pledge(2)</a>es\sin\seffect\sthat\sare\srestricting\sthe\susage\sof\snetwork\sfunctions\sthen\sTcl_MakeFileChannel\swill\ssegfault\swhen\sit\stries\sto\suse\sgetsockname(2)\sto\scheck\sif\sthe\sfd\sis\sa\ssocket.\r\n<br>\r\nAn\simportant\stime\swhen\sthis\shappens\sis\swhen\stclsh\sis\sfed\sa\sscript\son\sstdin:\stclsh\swill\simmediately\ssegfault.\r\n<br>\r\nBy\susing\sfstat(2)\sto\sfirst\scheck\sif\sthe\sfd\sis\sa\ssocket,\sa\scall\sto\sgetsockname\smight\sbe\savoided.\r\n<br>\r\nThis\smay\shave\ssecurity\simplications.\r\n<br><br>\r\nAttached\sis\sa\spatch.\r\n<br>\r\nThe\spatch\shas\sthe\snice\sside\seffect\sof\sputting\sall\sthe\ssocket\sbits\sin\sone\splace.\r\n<br><br>\r\nHere\sis\sa\stest\sprogram:\r\n<pre>\r\n#include\s<unistd.h>\r\n#define\sTCLSH\s"/usr/local/bin/tclsh"\r\nint\smain\s(int\sargc,\schar\s*argv[])\s{\r\n\s\s\s\s\s\s\s\schar\s*a[]\s=\s{\sTCLSH,\sNULL\s};\r\n\s\s\s\s\s\s\s\schar\s*e[]\s=\s{\sNULL\s};\r\n\r\n#ifdef\sDNS\r\n\s\s\s\s\s\s\s\spledge(NULL,\s"stdio\srpath\sgetpw\sdns");\r\n#else\r\n#\sifdef\sINET\r\n\s\s\s\s\s\s\s\spledge(NULL,\s"stdio\srpath\sgetpw\sinet");\r\n#\selse\r\n\s\s\s\s\s\s\s\spledge(NULL,\s"stdio\srpath\sgetpw");\r\n#\sendif\r\n#endif\r\n\r\n\s\s\s\s\s\s\s\sexecve(TCLSH,\sa,\se);\r\n\s\s\s\s\s\s\s\sreturn\s0;\r\n}\r\n</pre>\r\n\r\nBuild\swith\sno\s-D's:\r\n<pre>\r\n$\scc\s-o\stpl\stpl.c\r\n$\secho\s'puts\smoo'\s|\s./tpl\r\nAbort\strap\s(core\sdumped)\s\r\n</pre>\r\n\r\nBuild\swith\seither\s-DINET\sor\s-DDNS:\r\n<pre>\r\n$\scc\s-o\stpl\stpl.c\s-DINET\r\n$\secho\s'puts\smoo'\s|\s./tpl\r\nmoo\r\n</pre>
J foundin 8.6.*
J is_private 0
J login stu
J priority 5\sMedium
J private_contact 702b65e835b7b4b4720d6e9d37fc582f82909394
J resolution None
J severity Minor
J status Open
J submitter stu
J subsystem 38.\sInit\s-\sLibrary\s-\sAutoload
J title Don't\scall\sgetsockname(2)\sin\sTcl_MakeFileChannel(3)\sunless\sabsolutely\snecessary
J type RFE
K 0ac9d06895f000b3c83fcb6b14940acc79f11122
U stu
Z 8b937bdbd4c4e0ecdd777d6c1f358c0d