diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-03-27 14:45:59 +0000 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-03-28 09:41:54 +0100 |
commit | 303ed9a9646256eb6841a21bab4a7fdfd3a0dc53 (patch) | |
tree | 01a8525fd252287b95efa0f797b6a8824459c1b1 /external/python3/init-sys-streams-cant-initialize-stdin.patch.0 | |
parent | 460a7103664ac8dc60e260c56e5113d689b8072f (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/+/165327
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'external/python3/init-sys-streams-cant-initialize-stdin.patch.0')
-rw-r--r-- | external/python3/init-sys-streams-cant-initialize-stdin.patch.0 | 43 |
1 files changed, 43 insertions, 0 deletions
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) { |