NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/56254: script(1) abuses non-async-signal-safe functions in signal handlers



The following reply was made to PR bin/56254; it has been noted by GNATS.

From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/56254: script(1) abuses non-async-signal-safe functions in
 signal handlers
Date: Thu, 17 Jun 2021 07:17:31 +0000 (UTC)

 On Thu, 17 Jun 2021, campbell+netbsd%mumble.net@localhost wrote:
 
 > The script(1) command sets up signal handlers that call functions which are not async-signal-safe, such as exit():
 >
 > https://nxr.netbsd.org/xref/src/usr.bin/script/script.c?r=1.28#182
 > https://nxr.netbsd.org/xref/src/usr.bin/script/script.c?r=1.28#232
 > https://nxr.netbsd.org/xref/src/usr.bin/script/script.c?r=1.28#333
 >
 > This can cause a deadlock in rtld:
 >
 > https://mail-index.netbsd.org/current-users/2021/06/14/msg041121.html
 >
 > script(1) should use only async-signal-safe functions in signal handlers -- for example, it could set a flag in the signal handler and check the flags whenever any blocking syscall fails with EINTR.
 >
 
 Since script(1) a) isn't using atexit() and b) is flushing the script
 file, I think we can just use _exit() instead of exit() here:
 
 diff -urN a/script/script.c b/script/script.c
 --- a/script/script.c	2020-08-31 15:32:15.000000000 +0000
 +++ b/script/script.c	2021-06-17 06:51:13.253662302 +0000
 @@ -330,7 +330,7 @@
   		if (!quiet)
   			(void)printf("Script done, output file is %s\n", fname);
   	}
 -	exit(EXIT_SUCCESS);
 +	_exit(EXIT_SUCCESS);
   }
 
   static void
 
 Otherwise, I have a more elaborate version (the std. sig_t() -> flag ->
 check_flag_in_main -> exit() stuff) which I can supply.
 
 Much thanks to riastradh@ for spotting the _real issue_ causing this PR.
 
 -RVP
 


Home | Main Index | Thread Index | Old Index