summaryrefslogtreecommitdiff
path: root/external/python3/init-sys-streams-cant-initialize-stdin.patch.0
blob: fa23b27fae8442b4772bed0f95b18a4439d59219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--- Python/pylifecycle.c	2024-03-27 14:34:43.905367358 +0000
+++ Python/pylifecycle.c	2024-03-27 14:40:16.339134322 +0000
@@ -1789,6 +1789,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
@@ -2335,19 +2335,6 @@
     PyStatus res = _PyStatus_OK();
     const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
 
-    /* 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
-
     if (!(iomod = PyImport_ImportModule("io"))) {
         goto error;
     }