The sender domain has a DMARC Reject/Quarantine policy which disallows
sending mailing list messages using the original "From" header.
To mitigate this problem, the original message has been wrapped
automatically by the mailing list software.
--- Begin Message ---
Em 28/08/2023 11:12, Markus Gothe escreveu:
Fix retriggering of init.d-scripts which calls
commands dependent on functional STDIN/STDOUT/STDERR.
Yeah, it is no fun when some library decides to become allergic to one
of FD0-2 being closed, and a O.S. update suddenly exposes this issue.
Been there, suffered through it, learned from it.
So, this is right up there in the "Just don't do it" list, right after
calling execve() with NULL for argv[0]. Avoid closed FDs 0-2 at program
start like the plague: fix it first thing. Never execve() anything with
closed FDs 0-2 in the general case.
It is also true for shell scripts: don't close FDs 0-2, redirect them
to/from /dev/null instead. Don't repurpose them, either.
Data corruption (due to unexpected writes from just about anything) is a
possible outcome of running stuff with FDs 0-2 closed or repurposed,
BTW. Consider yourself lucky when things just crash or exit with an
error, instead.
IMHO, if they're not doing it already, ubus and all its helpers, such as
rpcd, should be defensive about FDs 0-2 and ensure they are always
properly open (to /dev/null if need be), preferably at program start,
and certainly when they are about to execve() anything.
PS: I have attached an example of how one could do generic self-healing
of the standard low FDs in C in a POSIX environment where fcntl() and
dup2() are available. Note that FD 2 is expected to be R/W, according
to the C specification for stdio.h streams.
--
Henrique de Moraes Holschuh
Analista de Projetos
Centro de Estudos e Pesquisas em Tecnologias de Redes e Operações
(Ceptro.br)
+55 11 5509-3537 R.:4023
INOC 22548*625
www.nic.br
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h> /* for strerror() */
static int is_valid_fd(const int fd)
{
return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
}
static void fix_fds(const int fd, const int fl)
{
int nfd;
if (is_valid_fd(fd))
return;
nfd = open("/dev/null", fl);
if (nfd == -1 || dup2(nfd, fd) == -1) {
/* *if* stderr is not closed, try to explain what happened */
fprintf(stderr, "could not attach /dev/null to file descriptor %d: %s\n",
fd, strerror(errno));
/* if (nfd != -1) close(nfd); - disabled as we're going to exit() now */
exit(EXIT_FAILURE);
}
if (nfd != fd)
close(nfd);
}
/*
* Run this *first thing* in main(), and no later.
* You have been warned.
*
* Also, avoid execve()'ing things with FDs 0-2 closed unless you *really*
* know better. Don't repurpose those FDs either, it is an extremely bad
* idea in the general case.
*/
static void sanitize_std_fds(void)
{
/* do it in file descriptor numerical order! */
fix_fds(STDIN_FILENO, O_RDONLY);
fix_fds(STDOUT_FILENO, O_WRONLY);
fix_fds(STDERR_FILENO, O_RDWR);
}
int main(void)
{
sanitize_std_fds();
return EXIT_SUCCESS;
}
--- End Message ---
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel