Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport some fixes to 3.4 #205

Merged
merged 6 commits into from
Apr 7, 2024
Merged

Conversation

dscho
Copy link
Collaborator

@dscho dscho commented Mar 3, 2024

The main reason for this is to verify the proposed fix for #202. While at it, I'll include a couple other fixes for potential hangs.

@dscho dscho self-assigned this Mar 3, 2024
@dscho dscho marked this pull request as ready for review March 3, 2024 09:18
@dscho dscho force-pushed the backport-fixes-to-3.4 branch from 9c7403d to f30ee6b Compare March 3, 2024 09:20
@dscho
Copy link
Collaborator Author

dscho commented Mar 3, 2024

Here is the range-diff relative to the commits in cygwin-3_5-branch
  • 1: aa73e11 ! 1: 621831b Cygwin: console: Fix exit code for non-cygwin process.

    @@ Commit message
         other terminals."), that the pointer cons is accessed before fixing
         when it is NULL. This patch fixes the issue.
     
    +    Backported-from: aa73e11524 (Cygwin: console: Fix exit code for non-cygwin process., 2024-02-02)
         Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from other terminals.")
         Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
         Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
    +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
     
      ## winsup/cygwin/fhandler/console.cc ##
     @@ winsup/cygwin/fhandler/console.cc: fhandler_console::need_console_handler ()
      void
      fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons)
      {
    --  const _minor_t unit = cons->get_minor ();
     -  if (con.disable_master_thread == x)
     -    return;
        if (cons == NULL)
    @@ winsup/cygwin/fhandler/console.cc: fhandler_console::set_disable_master_thread (
            else
      	return;
          }
    -+  const _minor_t unit = cons->get_minor ();
     +  if (con.disable_master_thread == x)
     +    return;
        cons->acquire_input_mutex (mutex_timeout);
  • 2: 9bcfd06 ! 2: 074a644 Cygwin: console: Avoid slipping past disable_master_thread check.

    @@ Commit message
         processed once after setting disable_master_thread flag. This patch
         prevents that.
     
    +    Backported-from: 9bcfd06045 (Cygwin: console: Avoid slipping past disable_master_thread check., 2024-02-03)
         Fixes: d4aacd50e6cf ("Cygwin: console: Add missing input_mutex guard.")
         Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
    +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
     
      ## winsup/cygwin/fhandler/console.cc ##
     @@ winsup/cygwin/fhandler/console.cc: fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
    @@ winsup/cygwin/fhandler/console.cc: fhandler_console::cons_master_thread (handle_
            switch (cygwait (p->input_handle, (DWORD) 0))
      	{
     @@ winsup/cygwin/fhandler/console.cc: fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons)
    +       else
      	return;
          }
    -   const _minor_t unit = cons->get_minor ();
     -  if (con.disable_master_thread == x)
     -    return;
        cons->acquire_input_mutex (mutex_timeout);
  • 9: a6ac7b4 ! 3: 4746257 Cygwin: pty: Fix handle leak in master process.

    @@ Commit message
     
         /~https://github.com/msys2/msys2-runtime/issues/198
     
    +    Backported-from: a6ac7b4138 (Cygwin: pty: Fix handle leak in master process., 2024-02-13)
         Fixes: 29431fcb5b14 ("Cygwin: pty: Inherit typeahead data between two input pipes.")
         Reported-by: Hakkin Lain
         Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
    +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
     
      ## winsup/cygwin/fhandler/pty.cc ##
     @@ winsup/cygwin/fhandler/pty.cc: fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp,
    @@ winsup/cygwin/fhandler/pty.cc: fhandler_pty_slave::transfer_input (tty::xfer_dir
      
        /* Fix input_available_event which indicates availability in cyg pipe. */
        if (dir == tty::to_nat) /* all data is transfered to nat pipe,
    -
    - ## winsup/cygwin/release/3.5.1 ##
    -@@ winsup/cygwin/release/3.5.1: Fixes:
    -   error mode is now possible by using the new CYGWIN environment variable
    -   option "winjitdebug".
    -   Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255305.html
    -+
    -+- Fix handle leak in pty master which occurs when non-cygwin process
    -+  is started in pty.
    -+  Addresses: /~https://github.com/msys2/msys2-runtime/issues/198
  • 10: 73cd80c ! 4: 8b35e90 Cygwin: pty: Fix potential handle leak regarding CallNamedPipe().

    @@ Commit message
         requests that. Though some of them are not used so should be closed,
         they were not. This causes handle leak potentially.
     
    +    Backported-from: 73cd80c976 (Cygwin: pty: Fix potential handle leak regarding CallNamedPipe()., 2024-02-13)
         Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
    +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
     
      ## winsup/cygwin/fhandler/pty.cc ##
     @@ winsup/cygwin/fhandler/pty.cc: fhandler_pty_slave::open (int flags, mode_t)
  • 11: 02f7f65 ! 5: 6db75ee Cygwin: console: Make VMIN and VTIME work.

    @@ Commit message
     
         Previously, VMIN and VTIME did not work at all. This patch fixes that.
     
    +    Backported-from: 73cd80c976 (Cygwin: pty: Fix potential handle leak regarding CallNamedPipe()., 2024-02-13)
         Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
    +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
     
      ## winsup/cygwin/fhandler/console.cc ##
     @@ winsup/cygwin/fhandler/console.cc: fhandler_console::read (void *pv, size_t& buflen)
    @@ winsup/cygwin/fhandler/console.cc: wait_retry:
      #undef buf
      
        buflen = copied_chars;
    -
    - ## winsup/cygwin/release/3.5.1 ##
    -@@ winsup/cygwin/release/3.5.1: Fixes:
    - - Fix handle leak in pty master which occurs when non-cygwin process
    -   is started in pty.
    -   Addresses: /~https://github.com/msys2/msys2-runtime/issues/198
    -+
    -+- Fix the problem that VMIN and VTIME does not work at all in console.
  • -: ---------- > 6: f30ee6b Cygwin: pipe: Give up to use query_hdl for non-cygwin apps.

@lazka
Copy link
Member

lazka commented Apr 7, 2024

Sorry I forgot about this.

lgtm

tyan0 added 6 commits April 7, 2024 15:19
If non-cygwin process is executed in console, the exit code is not
set correctly. This is because the stub process for non-cygwin app
crashes in fhandler_console::set_disable_master_thread() due to NULL
pointer dereference. This bug was introduced by the commit:
3721a75 ("Cygwin: console: Make the console accessible from
other terminals."), that the pointer cons is accessed before fixing
when it is NULL. This patch fixes the issue.

Backported-from: aa73e11 (Cygwin: console: Fix exit code for non-cygwin process., 2024-02-02)
Fixes: 3721a75 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
If disable_master_thread flag is set between the code checking that
flag not be set and the code acquiring input_mutex, input record is
processed once after setting disable_master_thread flag. This patch
prevents that.

Backported-from: 9bcfd06 (Cygwin: console: Avoid slipping past disable_master_thread check., 2024-02-03)
Fixes: d4aacd5 ("Cygwin: console: Add missing input_mutex guard.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
If non-cygwin process is started in pty, closing from_master_nat
pipe handle was missing in fhandler_pty_slave::input_transfer().
This occured because the handle was duplicated but not closed.

msys2#198

Backported-from: a6ac7b4 (Cygwin: pty: Fix handle leak in master process., 2024-02-13)
Fixes: 29431fc ("Cygwin: pty: Inherit typeahead data between two input pipes.")
Reported-by: Hakkin Lain
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
In pty master_thread, 6 handles are duplicated when CallNamedPipe()
requests that. Though some of them are not used so should be closed,
they were not. This causes handle leak potentially.

Backported-from: 73cd80c (Cygwin: pty: Fix potential handle leak regarding CallNamedPipe()., 2024-02-13)
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Previously, VMIN and VTIME did not work at all. This patch fixes that.

Backported-from: 73cd80c (Cygwin: pty: Fix potential handle leak regarding CallNamedPipe()., 2024-02-13)
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Non-cygwin app may call ReadFile() which makes NtQueryObject() for
ObjectNameInformation block in fhandler_pipe::get_query_hdl_per_process.
Therefore, stop to try to get query_hdl for non-cygwin apps.

Addresses: msys2#202

Backported-from: https://inbox.sourceware.org/cygwin-patches/20240303050915.2024-1-takashi.yano@nifty.ne.jp/
Fixes: b531d6b ("Cygwin: pipe: Introduce temporary query_hdl.")
Reported-by: Alisa Sireneva, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by:
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho dscho force-pushed the backport-fixes-to-3.4 branch from f30ee6b to 436c875 Compare April 7, 2024 13:19
@dscho dscho merged commit 436c875 into msys2:msys2-3.4.10 Apr 7, 2024
1 check passed
@dscho dscho deleted the backport-fixes-to-3.4 branch April 7, 2024 14:13
dscho added a commit to dscho/MSYS2-packages that referenced this pull request Apr 7, 2024
This corresponds to msys2/msys2-runtime#205.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/MSYS2-packages that referenced this pull request Jul 8, 2024
Looks like we haven't updated `MSYS2-packages`' `msys2-runtime-3.4`
directory in quite a while. This roll-up integrates:

- msys2/msys2-runtime#205
- msys2/msys2-runtime#209
- msys2/msys2-runtime#210
- msys2/msys2-runtime#192

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/MSYS2-packages that referenced this pull request Jul 9, 2024
Looks like we haven't updated `MSYS2-packages`' `msys2-runtime-3.4`
directory in quite a while. This roll-up integrates:

- msys2/msys2-runtime#192
- msys2/msys2-runtime#205
- msys2/msys2-runtime#209
- msys2/msys2-runtime#210
- msys2/msys2-runtime#220

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants