error.c: signal handler messages socket pair is disabled in Filan

This commit is contained in:
Gerhard Rieger 2022-08-12 12:33:32 +02:00
parent 9be423ceea
commit c62f93a168
3 changed files with 31 additions and 5 deletions

View file

@ -40,6 +40,10 @@ Corrections:
ctype(3) functions need there arguments to be unsigned char.
Thanks to Taylor R Campbell for sending a patch.
Filan library uses Socats diag/error message system and therefore had
always the signal handler messages socket pair open. This fix avoids
this socketpair in standalone Filan.
Porting:
OpenSSL, at least 1.1 on Ubuntu, crashed with SIGSEGV under certain
conditions: client connection to server with certificate with empty

25
error.c
View file

@ -37,6 +37,7 @@ struct diag_opts {
int exitstatus; /* pass signal number to error exit */
bool withhostname; /* in custom logs add hostname */
char *hostname;
bool signalsafe;
} ;
@ -44,7 +45,7 @@ static void _diag_exit(int status);
struct diag_opts diagopts =
{ NULL, E_ERROR, E_ERROR, 0, NULL, LOG_DAEMON, false, 0 } ;
{ NULL, E_ERROR, E_ERROR, 0, NULL, LOG_DAEMON, false, 0, false, NULL, true } ;
static void msg2(
#if HAVE_CLOCK_GETTIME
@ -134,15 +135,27 @@ static int diag_init(void) {
diaginitialized = 1;
/* gcc with GNU libc refuses to set this in the initializer */
diagopts.logfile = stderr;
if (diagopts.signalsafe) {
if (diag_sock_pair() < 0) {
return -1;
}
}
return 0;
}
#define DIAG_INIT ((void)(diaginitialized || diag_init()))
void diag_set(char what, const char *arg) {
switch (what) {
case 'I':
if (diagopts.signalsafe) {
if (diag_sock_send >= 0) { Close(diag_sock_send); diag_sock_send = -1; }
if (diag_sock_recv >= 0) { Close(diag_sock_recv); diag_sock_recv = -1; }
}
diagopts.signalsafe = false;
return;
}
DIAG_INIT;
switch (what) {
const struct wordent *keywd;
@ -240,7 +253,10 @@ int diag_reserve_fd(int fd) {
int diag_fork() {
Close(diag_sock_send);
Close(diag_sock_recv);
if (diagopts.signalsafe) {
return diag_sock_pair();
}
return 0;
}
/* Linux and AIX syslog format:
@ -281,7 +297,7 @@ void msg(int level, const char *format, ...) {
diag_dgram.level = level;
diag_dgram.exitcode = diagopts.exitstatus;
vsnprintf_r(diag_dgram.text, sizeof(diag_dgram.text), format, ap);
if (diag_in_handler && !diag_immediate_msg) {
if (diagopts.signalsafe && diag_in_handler && !diag_immediate_msg) {
send(diag_sock_send, &diag_dgram, sizeof(diag_dgram)-TEXTLEN + strlen(diag_dgram.text)+1,
0 /* for canonical reasons */
#ifdef MSG_DONTWAIT
@ -399,6 +415,11 @@ static void _msg(int level, const char *buff, const char *syslp) {
void diag_flush(void) {
struct diag_dgram recv_dgram;
char exitmsg[20];
if (!diagopts.signalsafe) {
return;
}
while (recv(diag_sock_recv, &recv_dgram, sizeof(recv_dgram)-1,
0 /* for canonical reasons */
#ifdef MSG_DONTWAIT

View file

@ -32,6 +32,7 @@ int main(int argc, const char *argv[]) {
const char *outfname = NULL;
unsigned long fildes;
diag_set('I', false);
diag_set('p', strchr(argv[0], '/') ? strrchr(argv[0], '/')+1 : argv[0]);
arg1 = argv+1; --argc;