diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-03-27 14:45:59 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2024-03-28 18:58:49 +0100 |
commit | dbe143087ddffa7cdeef3c155ac808dfcaa470fd (patch) | |
tree | ba45790e13ebfe5906d7775f3641955639173d91 | |
parent | c8fa7c01aa8a3e263c07b5cf4f72ace70f1d9308 (diff) |
python exits on initialization if fd 0 is a dir
which can happen if stdin was closed and the next
open was of a dir.
Later python checks for is_valid_fd, but an invalid fd
is not fatal for stdin, etc and it just return an empty
stdin wrapper, so move this check lower and do the same
for a dir.
Change-Id: Iaf8a48927b49408577ae7a781dfc6e0255a940cb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165326
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r-- | external/python3/UnpackedTarball_python3.mk | 1 | ||||
-rw-r--r-- | external/python3/init-sys-streams-cant-initialize-stdin.patch.0 | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/external/python3/UnpackedTarball_python3.mk b/external/python3/UnpackedTarball_python3.mk index 127dea4a8ee4..ca5b49d115c1 100644 --- a/external/python3/UnpackedTarball_python3.mk +++ b/external/python3/UnpackedTarball_python3.mk @@ -26,6 +26,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,python3,\ external/python3/darwin.patch.0 \ external/python3/macos-11.patch.0 \ external/python3/tsan.patch.0 \ + external/python3/init-sys-streams-cant-initialize-stdin.patch.0 \ )) ifneq ($(filter DRAGONFLY FREEBSD LINUX NETBSD OPENBSD SOLARIS,$(OS)),) diff --git a/external/python3/init-sys-streams-cant-initialize-stdin.patch.0 b/external/python3/init-sys-streams-cant-initialize-stdin.patch.0 new file mode 100644 index 000000000000..61b2464ab4b8 --- /dev/null +++ b/external/python3/init-sys-streams-cant-initialize-stdin.patch.0 @@ -0,0 +1,43 @@ +--- Python/pylifecycle.c 2024-03-27 14:34:43.905367358 +0000 ++++ Python/pylifecycle.c 2024-03-27 14:40:16.339134322 +0000 +@@ -1723,6 +1723,20 @@ + if (!is_valid_fd(fd)) + Py_RETURN_NONE; + ++ /* Check that stdin, etc is not a directory ++ Using shell redirection, you can redirect stdin to a directory, ++ crashing the Python interpreter. Catch this common mistake here ++ and output a useful error message. Note that under MS Windows, ++ the shell already prevents that. */ ++#ifndef MS_WINDOWS ++ struct _Py_stat_struct sb; ++ if (_Py_fstat_noraise(fd, &sb) == 0 && ++ S_ISDIR(sb.st_mode)) { ++ // "name" is a directory, cannot continue ++ Py_RETURN_NONE; ++ } ++#endif ++ + /* stdin is always opened in buffered mode, first because it shouldn't + make a difference in common use cases, second because TextIOWrapper + depends on the presence of a read1() method which only exists on +@@ -1854,19 +1868,6 @@ + PyStatus res = _PyStatus_OK(); + PyConfig *config = &interp->config; + +- /* Check that stdin is not a directory +- Using shell redirection, you can redirect stdin to a directory, +- crashing the Python interpreter. Catch this common mistake here +- and output a useful error message. Note that under MS Windows, +- the shell already prevents that. */ +-#ifndef MS_WINDOWS +- struct _Py_stat_struct sb; +- if (_Py_fstat_noraise(fileno(stdin), &sb) == 0 && +- S_ISDIR(sb.st_mode)) { +- return _PyStatus_ERR("<stdin> is a directory, cannot continue"); +- } +-#endif +- + /* Hack to avoid a nasty recursion issue when Python is invoked + in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ + if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) { |