]> sourceware.org Git - newlib-cygwin.git/commit
Cygwin: stat(): Fix "Bad address" error on stat() for /dev/tty.
authorTakashi Yano <takashi.yano@nifty.ne.jp>
Thu, 6 Jul 2023 21:11:52 +0000 (06:11 +0900)
committerTakashi Yano <takashi.yano@nifty.ne.jp>
Fri, 7 Jul 2023 23:03:16 +0000 (08:03 +0900)
commit3edb55af820025013b87fdb53249676067a8b8ee
tree67a51192fb92b980b2dbf64e59f9a44604201635
parente38f91d5a96c4554c69c833243e5afec8e3e90eb
Cygwin: stat(): Fix "Bad address" error on stat() for /dev/tty.

As reported in
https://cygwin.com/pipermail/cygwin/2023-June/253888.html,
"Bad address" error occurs when stat() is called after the commit
3721a756b0d8 ("Cygwin: console: Make the console accessible from
other terminals.").

There are two problems in the current code. One is fhandler_console::
fstat() calls get_ttyp()->getsid(). However, fh_alloc() in dtable.cc
omits to initialize the fhandler_console instance when stat() is
called. Due to this, get_ttyp() returns NULL and access violation
occurs. The other problem is fh_alloc() assigns fhandler_console
even if the CTTY is not a console. So the first problem above occurs
even if the CTTY is a pty.

This patch fixes the issue by:
1) Call set_unit() to initialize _tc if the get_ttyp() returns NULL.
2) Assign fhandler_pty_slave for /dev/tty if CTTY is a pty in fh_alloc().

Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible
  from other terminals.").
Fixes: 23771fa1f7028 ("dtable.cc (fh_alloc): Make different decisions
  when generating fhandler for not-opened devices. Add kludge to deal
  with opening /dev/tty.")
Reported-by: Bruce Jerrick <bmj001@gmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
winsup/cygwin/dtable.cc
winsup/cygwin/fhandler/console.cc
This page took 0.031839 seconds and 5 git commands to generate.