diff options
author | Ludovic Courtès <ludo@gnu.org> | 2022-08-05 12:35:36 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2022-08-05 14:20:51 +0200 |
commit | 56b1ea9002d2d3967b597aa0ee7595e815b21f23 (patch) | |
tree | ca6bae53db85ebe10026c191f58bb7f1cdb91340 | |
parent | 01e960edea3f61078f172e706b2c019c01d58107 (diff) | |
download | guile-56b1ea9002d2d3967b597aa0ee7595e815b21f23.tar.gz |
'system*' can no longer close file descriptor 2.
Fixes <https://bugs.gnu.org/55596>.
Reported by Hugo Nobrega <hugonobrega@ic.ufrj.br>
and Jack Hill <jackhill@jackhill.us>.
* libguile/posix.c (start_child): Close OUT only if it's greater than 2.
* test-suite/tests/posix.test ("system*")["exit code for nonexistent file"]
["https://bugs.gnu.org/55596"]: New tests.
-rw-r--r-- | libguile/posix.c | 5 | ||||
-rw-r--r-- | test-suite/tests/posix.test | 16 |
2 files changed, 17 insertions, 4 deletions
diff --git a/libguile/posix.c b/libguile/posix.c index 3ab12b99e..f4ca72d3e 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1,4 +1,4 @@ -/* Copyright 1995-2014,2016-2019,2021 +/* Copyright 1995-2014, 2016-2019, 2021-2022 Free Software Foundation, Inc. This file is part of Guile. @@ -1371,7 +1371,8 @@ start_child (const char *exec_file, char **exec_argv, if (err == 1) err = renumber_file_descriptor (err, err); do dup2 (out, 1); while (errno == EINTR); - close (out); + if (out > 2) + close (out); } if (err > 2) { diff --git a/test-suite/tests/posix.test b/test-suite/tests/posix.test index 1e552d16f..500dbb94a 100644 --- a/test-suite/tests/posix.test +++ b/test-suite/tests/posix.test @@ -1,6 +1,6 @@ ;;;; posix.test --- Test suite for Guile POSIX functions. -*- scheme -*- ;;;; -;;;; Copyright 2003-2004,2006-2007,2010,2012,2015,2017-2019,2021 +;;;; Copyright 2003-2004, 2006-2007, 2010, 2012, 2015, 2017-2019, 2021-2022 ;;;; Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or @@ -241,7 +241,19 @@ ;; `system*' would remain alive after an `execvp' failure. (let ((me (getpid))) (and (not (zero? (system* "something-that-does-not-exist"))) - (= me (getpid)))))) + (= me (getpid))))) + + (pass-if-equal "exit code for nonexistent file" + 127 ;aka. EX_NOTFOUND + (status:exit-val (system* "something-that-does-not-exist"))) + + (pass-if-equal "https://bugs.gnu.org/55596" + 127 + ;; The parameterization below used to cause 'start_child' to close + ;; fd 2 in the child process, which in turn would cause it to + ;; segfault, leading to a wrong exit code. + (parameterize ((current-output-port (current-error-port))) + (status:exit-val (system* "something-that-does-not-exist"))))) ;; ;; crypt |