[musl] Re: Tweaking the program name for <err.h> functions
Laurent Bercot
ska-dietlibc at skarnet.org
Mon Mar 11 21:21:00 UTC 2024
>(Aside: making _FORTIFY_SOURCE>1 trap close(n) with n<3 would be an
>interesting idea... :)
Please don't. close(0); if (open("something", O_RDONLY)) fail();
(only when single-threaded, obviously) is a valid pattern, and uses
one fewer descriptor than fd=open("something", O_RDONLY); dup2(fd, 0);
Also, running with stdin or stdout closed (or even stderr but what kind
of monster would do that) is fine for a process that is internal to a
project, that isn't user-facing; it's on the project to know the fd
states of its various components. Private APIs should not have the same
constraints as public ones.
(And yes, for user-facing programs, i.e. 99% of them, it is a good
idea to always sanitize around 0, 1 and 2.)
--
Laurent
More information about the libbsd
mailing list