]> git.pld-linux.org Git - packages/glib2.git/blob - revert-fd-collision-handling.patch
R: pcre2-8-static in -static
[packages/glib2.git] / revert-fd-collision-handling.patch
1 From 2a36bb4b7e46f9ac043561c61f9a790786a5440c Mon Sep 17 00:00:00 2001
2 From: Ray Strode <rstrode@redhat.com>
3 Date: Fri, 28 Oct 2022 11:21:04 -0400
4 Subject: [PATCH 1/2] Revert "Handling collision between standard i/o file
5  descriptors and newly created ones"
6
7 g_unix_open_pipe tries to avoid the standard io fd range
8 when getting pipe fds. This turns out to be a bad idea because
9 certain buggy programs rely on it using that range.
10
11 This reverts commit d9ba6150909818beb05573f54f26232063492c5b
12
13 Closes: #2795
14 Reopens: #16
15 ---
16  glib/glib-unix.c | 24 ------------------------
17  1 file changed, 24 deletions(-)
18
19 diff --git a/glib/glib-unix.c b/glib/glib-unix.c
20 index 4710c51168..bc152d7663 100644
21 --- a/glib/glib-unix.c
22 +++ b/glib/glib-unix.c
23 @@ -108,17 +108,6 @@ g_unix_open_pipe (int     *fds,
24      ecode = pipe2 (fds, pipe2_flags);
25      if (ecode == -1 && errno != ENOSYS)
26        return g_unix_set_error_from_errno (error, errno);
27 -    /* Don't reassign pipes to stdin, stdout, stderr if closed meanwhile */
28 -    else if (fds[0] < 3 || fds[1] < 3)
29 -      {
30 -        int old_fds[2] = { fds[0], fds[1] };
31 -        gboolean result = g_unix_open_pipe (fds, flags, error);
32 -        close (old_fds[0]);
33 -        close (old_fds[1]);
34 -
35 -        if (!result)
36 -          g_unix_set_error_from_errno (error, errno);
37 -      }
38      else if (ecode == 0)
39        return TRUE;
40      /* Fall through on -ENOSYS, we must be running on an old kernel */
41 @@ -127,19 +116,6 @@ g_unix_open_pipe (int     *fds,
42    ecode = pipe (fds);
43    if (ecode == -1)
44      return g_unix_set_error_from_errno (error, errno);
45 -  /* Don't reassign pipes to stdin, stdout, stderr if closed meanwhile */
46 -  else if (fds[0] < 3 || fds[1] < 3)
47 -    {
48 -      int old_fds[2] = { fds[0], fds[1] };
49 -      gboolean result = g_unix_open_pipe (fds, flags, error);
50 -      close (old_fds[0]);
51 -      close (old_fds[1]);
52 -
53 -      if (!result)
54 -        g_unix_set_error_from_errno (error, errno);
55 -
56 -      return result;
57 -    }
58  
59    if (flags == 0)
60      return TRUE;
61 -- 
62 GitLab
63
64
65 From 1c1c452ff2030135e4abc2816e81b7078a845580 Mon Sep 17 00:00:00 2001
66 From: Ray Strode <rstrode@redhat.com>
67 Date: Mon, 31 Oct 2022 09:17:55 -0400
68 Subject: [PATCH 2/2] glib-unix: Add test to make sure g_unix_open_pipe will
69  intrude standard range
70
71 Now that we know it's a bad idea to avoid the standard io fd range
72 when getting pipe fds for g_unix_open_pipe, we should test to make sure
73 we don't inadvertently try to do it again.
74
75 This commit adds that test.
76 ---
77  glib/tests/unix.c | 41 +++++++++++++++++++++++++++++++++++++++++
78  1 file changed, 41 insertions(+)
79
80 diff --git a/glib/tests/unix.c b/glib/tests/unix.c
81 index 2112cab6bf..6c4a59dee7 100644
82 --- a/glib/tests/unix.c
83 +++ b/glib/tests/unix.c
84 @@ -24,8 +24,11 @@
85  #include "config.h"
86  
87  #include "glib-unix.h"
88 +#include "gstdio.h"
89 +
90  #include <string.h>
91  #include <pwd.h>
92 +#include <unistd.h>
93  
94  static void
95  test_pipe (void)
96 @@ -52,6 +55,43 @@ test_pipe (void)
97    g_assert (g_str_has_prefix (buf, "hello"));
98  }
99  
100 +static void
101 +test_pipe_stdio_overwrite (void)
102 +{
103 +  GError *error = NULL;
104 +  int pipefd[2], ret;
105 +  gboolean res;
106 +  int stdin_fd;
107 +
108 +
109 +  g_test_summary ("Test that g_unix_open_pipe() will use the first available FD, even if it’s stdin/stdout/stderr");
110 +  g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2795");
111 +
112 +  stdin_fd = dup (STDIN_FILENO);
113 +  g_assert_cmpint (stdin_fd, >, 0);
114 +
115 +  g_close (STDIN_FILENO, &error);
116 +  g_assert_no_error (error);
117 +
118 +  res = g_unix_open_pipe (pipefd, FD_CLOEXEC, &error);
119 +  g_assert_no_error (error);
120 +  g_assert_true (res);
121 +
122 +  g_assert_cmpint (pipefd[0], ==, STDIN_FILENO);
123 +
124 +  g_close (pipefd[0], &error);
125 +  g_assert_no_error (error);
126 +
127 +  g_close (pipefd[1], &error);
128 +  g_assert_no_error (error);
129 +
130 +  ret = dup2 (stdin_fd, STDIN_FILENO);
131 +  g_assert_cmpint (ret, >=, 0);
132 +
133 +  g_close (stdin_fd, &error);
134 +  g_assert_no_error (error);
135 +}
136 +
137  static void
138  test_error (void)
139  {
140 @@ -337,6 +377,7 @@ main (int   argc,
141    g_test_init (&argc, &argv, NULL);
142  
143    g_test_add_func ("/glib-unix/pipe", test_pipe);
144 +  g_test_add_func ("/glib-unix/pipe-stdio-overwrite", test_pipe_stdio_overwrite);
145    g_test_add_func ("/glib-unix/error", test_error);
146    g_test_add_func ("/glib-unix/nonblocking", test_nonblocking);
147    g_test_add_func ("/glib-unix/sighup", test_sighup);
148 -- 
149 GitLab
150
This page took 0.058034 seconds and 3 git commands to generate.