Nim/lib/pure
alaviss 1bdc30bdb1
Make file descriptors from stdlib non-inheritable by default (#13201)
* io: make file descriptors non-inheritable by default

This prevents file descriptors/handles leakage to child processes
that might cause issues like running out of file descriptors, or potential
security issues like leaking a file descriptor to a restricted file.

While this breaks backward compatibility, I'm rather certain that not
many programs (if any) actually make use of this implementation detail.
A new API `setInheritable` is provided for the few that actually want to
use this functionality.

* io: disable inheritance at file creation time for supported platforms

Some platforms provide extension to fopen-family of functions to allow
for disabling descriptor inheritance atomically during File creation.
This guards against possible leaks when a child process is spawned
before we managed to disable the file descriptor inheritance
(ie. in a multi-threaded program).

* net, nativesockets: make sockets non inheritable by default

With this commit, sockets will no longer leak to child processes when
you don't want it to. Should solves a lot of "address in use" that might
occur when your server has just restarted.

All APIs that create sockets in these modules now expose a `inheritable`
flag that allow users to toggle inheritance for the resulting sockets.
An implementation of `setInheritance()` is also provided for SocketHandle.

While atomically disabling inheritance at creation time is supported on
Windows, it's only implemented by native winsock2, which is too much for
now. This support can be implemented in a future patch.

* posix: add F_DUPFD_CLOEXEC

This command duplicates file descriptor with close-on-exec flag set.

Defined in POSIX.1-2008.

* ioselectors_kqueue: don't leak file descriptors

File descriptors internally used by ioselectors on BSD/OSX are now
shielded from leakage.

* posix: add O_CLOEXEC

This flag allows file descriptors to be open() with close-on-exec flag
set atomically.

This flag is specified in POSIX.1-2008

* tfdleak: test for selectors leakage

Also simplified the test by using handle-type agnostic APIs to test for
validity.

* ioselectors_epoll: mark all fd created close-on-exec

File descriptors from ioselectors should no longer leaks on Linux.

* tfdleak: don't check for selector leakage on Windows

The getFd proc for ioselectors_select returns a hardcoded -1

* io: add NoInheritFlag at compile time

* io: add support for ioctl-based close-on-exec

This allows for the flag to be set/unset in one syscall. While the
performance gains might be negliable, we have one less failure point
to deal with.

* tfdleak: add a test for setInheritable

* stdlib: add nimInheritHandles to restore old behaviors

* memfiles: make file handle not inheritable by default for posix

* io: setInheritable now operates on OS file handle

On Windows, the native handle is the only thing that's inheritable, thus
we can assume that users of this function will already have the handle
available to them. This also allows users to pass down file descriptors
from memfiles on Windows with ease, should that be desired.

With this, nativesockets.setInheritable can be made much simpler.

* changelog: clarify

* nativesockets: document setInheritable return value

* posix_utils: atomically disable fd inheritance for mkstemp
2020-04-20 17:09:59 +02:00
..
collections Add runnableExamples to critbits module (#13994) 2020-04-18 20:06:20 +02:00
concurrency Step2: fixes #13781, fixes #13805 (#13897) 2020-04-16 23:27:08 +02:00
includes forward type alignment information to seqs (#12430) 2020-04-19 07:52:01 +02:00
ioselects Make file descriptors from stdlib non-inheritable by default (#13201) 2020-04-20 17:09:59 +02:00
unidecode fix unidecode.unidecode example input string 2019-04-20 21:10:52 -05:00
algorithm.nim [backport] fix #13352 2020-02-07 18:26:08 +01:00
async.nim Unify async macro and futures for js and native targets 2018-01-05 16:40:51 +02:00
asyncdispatch.nim asyncdispatch: get rid of erroneous set constructions (#13877) 2020-04-05 08:39:43 +02:00
asyncdispatch.nim.cfg Rename *.nimrod.cfg to *.nim.cfg 2015-02-03 09:04:24 +01:00
asyncfile.nim ARC works for async on Windows (#13179) 2020-01-17 11:14:17 +01:00
asyncftpclient.nim Fixes asyncftpclient multiline reading, fixes #4684 (#13242) 2020-01-24 00:18:16 +01:00
asyncfutures.nim cycle breaker (#13593) 2020-03-19 22:58:16 +01:00
asynchttpserver.nim Add isNil check to custom Content-Length. (#13867) [backport:1.2] 2020-04-05 09:02:30 +02:00
asyncmacro.nim Fix #13889 with testcase (#13896) [backport] 2020-04-06 16:25:24 +02:00
asyncnet.nim introduce getPeerCertificates, fixes #13299 (#13650) 2020-03-22 21:00:37 +01:00
asyncstreams.nim asyncstreams: replace unintended link with emphasis 2019-10-22 17:59:12 -07:00
base64.nim encodeMIME should be encodeMime by our coding guidelines 2020-04-01 14:10:27 +02:00
bitops.nim Make bitand, bitor, bitxor varargs-friendly (#13985) 2020-04-20 14:48:37 +02:00
browsers.nim openDefaultBrowser now works on OSX (#13892) [backport] 2020-04-06 08:26:12 +02:00
cgi.nim [backport] run nimpretty on the remaining files 2019-09-30 13:58:17 +02:00
colors.nim [backport] print more information for the previous commit 2019-11-06 16:14:28 +01:00
complex.nim [backport] fix #12528, fix #12525: incorrect generic type resolution for default values (#12538) 2019-10-28 16:56:38 +01:00
cookies.nim make more tests green 2018-04-30 02:52:58 +02:00
coro.nim [backport] run nimpretty on the remaining files 2019-09-30 13:58:17 +02:00
coro.nimcfg fix test failure in coro.nim 2015-10-01 12:05:45 -07:00
cstrutils.nim move eqIdent to vm.nim (#7585) 2018-04-15 23:38:43 +02:00
db_common.nim [backport] run nimpretty on the remaining files 2019-09-30 13:58:17 +02:00
distros.nim Detect Ubuntu by checking release() and uname() (#13704) 2020-03-20 10:59:05 +01:00
dynlib.nim [backport] run nimpretty on os-related stuff 2019-09-30 13:58:15 +02:00
encodings.nim fix #13218: avoid some irrelevant warnings for nim doc,rst2html,--app:lib, + other fixes (#13550) 2020-03-13 20:42:41 +01:00
endians.nim [backport] run nimpretty on os-related stuff 2019-09-30 13:58:15 +02:00
fenv.nim Deprecate DCE:on (#13839) 2020-04-02 02:58:43 +02:00
future.nim renamed future.nim to sugar.nim 2018-04-06 11:59:49 +02:00
hashes.nim fixes #12834 (#14017) 2020-04-19 14:42:45 +02:00
htmlgen.nim fixes #13444 2020-02-21 16:58:30 +01:00
htmlparser.nim [backport] run nimpretty on parsers 2019-09-30 13:58:08 +02:00
httpclient.nim fix #13894, httpclient hang on Http204 2020-04-07 22:21:39 +01:00
httpcore.nim httpcore: deprecate ==(string, HttpCode) (#13682) 2020-03-19 09:07:44 +01:00
json.nim json doc: Note about Option and reserved keywords (#13895) 2020-04-07 15:14:25 +02:00
lenientops.nim fix #13218: avoid some irrelevant warnings for nim doc,rst2html,--app:lib, + other fixes (#13550) 2020-03-13 20:42:41 +01:00
lexbase.nim [backport] run nimpretty on parsers 2019-09-30 13:58:08 +02:00
logging.nim [backport] run nimpretty on the remaining files 2019-09-30 13:58:17 +02:00
marshal.nim fixes #13863 (#13929) 2020-04-08 19:51:23 +02:00
math.nim style fix: change 'JS' to 'js' to make it consistent (#13168) 2020-01-16 14:14:03 +01:00
md5.nim [backport] run nimpretty on hashes 2019-09-30 13:58:10 +02:00
memfiles.nim Make file descriptors from stdlib non-inheritable by default (#13201) 2020-04-20 17:09:59 +02:00
mersenne.nim Add Documentation (#13811) 2020-03-31 15:47:57 +02:00
mimetypes.nim Add Documentation (#13811) 2020-03-31 15:47:57 +02:00
nativesockets.nim Make file descriptors from stdlib non-inheritable by default (#13201) 2020-04-20 17:09:59 +02:00
net.nim Make file descriptors from stdlib non-inheritable by default (#13201) 2020-04-20 17:09:59 +02:00
nimprof.nim fix deprecations and other warnings (#13748) 2020-03-25 19:15:34 +01:00
nimprof.nim.cfg Rename *.nimrod.cfg to *.nim.cfg 2015-02-03 09:04:24 +01:00
nimtracker.nim make memory tracker work without onThreadCreation 2017-03-14 15:45:35 +01:00
oids.nim [backport] run nimpretty on hashes 2019-09-30 13:58:10 +02:00
options.nim Consider proc as a pointer type in options (#13460) 2020-02-21 23:14:55 +01:00
os.nim #13806 - getApplFreebsd might lose data (#13807) 2020-03-31 15:50:24 +02:00
osproc.nim osproc: added a better version of waitForExit for Haiku (#13938) 2020-04-10 09:34:52 +02:00
oswalkdir.nim fix #11458 oswalkdir (#13689) 2020-03-19 10:23:05 +01:00
parsecfg.nim Fix typo for literal [ (#13243) 2020-01-24 08:42:03 +00:00
parsecsv.nim revert stdlib changes which are not required anymore 2020-04-01 19:38:44 +02:00
parsejson.nim fixed to jsonArrayEnd comment. (#13624) 2020-03-11 08:26:10 +01:00
parseopt.nim Fixes ambiguity errors when evaluating Nimble files. (#12674) [backport] 2019-11-18 09:26:06 +01:00
parsesql.nim [backport] run nimpretty on parsers 2019-09-30 13:58:08 +02:00
parseutils.nim Deprecate DCE:on (#13839) 2020-04-02 02:58:43 +02:00
parsexml.nim make parsexml compatible with --gc:destructors/newruntime 2019-11-07 18:18:51 +01:00
pathnorm.nim fix #13579 joinPath("/foo/", "../a") is now /a (#13586) 2020-03-05 15:31:22 +01:00
pegs.nim Update pegs.nim to work at compiletime. No range errors. (#13459) 2020-02-27 11:08:57 +01:00
punycode.nim Add Documentation (#13811) 2020-03-31 15:47:57 +02:00
random.nim style fix: change 'JS' to 'js' to make it consistent (#13168) 2020-01-16 14:14:03 +01:00
rationals.nim [backport] run nimpretty on numbers stuff 2019-09-30 13:58:05 +02:00
reservedmem.nim [backport] run nimpretty on string stuff 2019-09-30 13:58:13 +02:00
ropes.nim Deprecate DCE:on (#13839) 2020-04-02 02:58:43 +02:00
segfaults.nim [backport] run nimpretty on os-related stuff 2019-09-30 13:58:15 +02:00
selectors.nim fix #13218: avoid some irrelevant warnings for nim doc,rst2html,--app:lib, + other fixes (#13550) 2020-03-13 20:42:41 +01:00
smtp.nim [backport] run nimpretty on web stuff 2019-09-30 13:58:11 +02:00
smtp.nim.cfg revert moving oids and smtp to graveyard 2019-01-11 08:51:19 +01:00
ssl_certs.nim ssl_certs: add Haiku support (#13761) 2020-03-26 14:47:15 +01:00
stats.nim Documentation, add more examples (#13825) 2020-04-01 19:39:58 +02:00
streams.nim Added fix for handling TaintedStrings in streams and httpclient (#12969) 2019-12-29 17:37:22 +01:00
strformat.nim fix #13218: avoid some irrelevant warnings for nim doc,rst2html,--app:lib, + other fixes (#13550) 2020-03-13 20:42:41 +01:00
strmisc.nim Deprecate DCE:on (#13839) 2020-04-02 02:58:43 +02:00
strscans.nim fix a few dead links and a missing sentence in documentation (#12387) 2019-10-08 15:24:34 -04:00
strtabs.nim fixes #12996 2020-01-05 09:42:44 +01:00
strutils.nim Tiny since cleanup (#13286) 2020-01-28 20:02:07 +01:00
sugar.nim Add hashWangYi1 (#13823) 2020-04-15 20:11:18 +02:00
terminal.nim nimgrep improvements (#12779) 2019-12-05 14:42:20 +01:00
times.nim fix https://github.com/nim-lang/RFCs/issues/211: var a: DateTime compiles and is usable (#14002) [backport:1.2] 2020-04-18 16:22:03 +02:00
typetraits.nim fix #12864 static params were mutating arg types during sigmatch; fix #12713 ; refs #13529 (#13976) 2020-04-14 15:00:02 +02:00
unicode.nim unicode: minor documention improvement 2020-04-20 08:42:08 +02:00
unittest.nim fix #6736: templates in unittest now show actual value (#13354) 2020-02-07 22:04:08 +01:00
uri.nim Add Data URI Base64, implements RFC-2397 (#13759) 2020-04-13 14:15:45 +01:00
volatile.nim Add volatile load/store (#5263) 2017-01-25 20:02:19 +01:00
xmlparser.nim [backport] run nimpretty on parsers 2019-09-30 13:58:08 +02:00
xmltree.nim xmltree: Make indentation consistent with any num of children nodes (#13482) 2020-02-26 11:41:44 +01:00