From ee705c1dcbf4576fc15ac5ed46426c859f08e686 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 17 Sep 2012 20:07:49 +0000 Subject: [PATCH] * pinfo.cc (pinfo::init): Detect potential race where short block has been retrieved but PID_EXECED flag is not set. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/pinfo.cc | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f12459ac1..d1c1b80a1 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2012-09-17 Christopher Faylor + + * pinfo.cc (pinfo::init): Detect potential race where short block has + been retrieved but PID_EXECED flag is not set. + 2012-09-13 Christopher Faylor * cygthread.cc (cygthread::stub): Remove old, unnecessary, FIXMEd code. diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index e8d156e04..de3620fdb 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -299,6 +299,15 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0) bool created = shloc != SH_JUSTOPEN; + /* Detect situation where a transitional memory block is being retrieved. + If the block has been allocated with PINFO_REDIR_SIZE but not yet + updated with a PID_EXECED state then we'll retry. */ + MEMORY_BASIC_INFORMATION mbi; + if (!created && procinfo->exists () + && VirtualQuery (procinfo, &mbi, sizeof (mbi)) + && mbi.RegionSize < sizeof (_pinfo)) + goto loop; + if (!created && createit && (procinfo->process_state & PID_REAPED)) { memset (procinfo, 0, sizeof (*procinfo));