This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Check for correct funtion entry address in munge_threadfunc


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=ff3c4a7d2fd686543140b0d39177c3464d1444e1

commit ff3c4a7d2fd686543140b0d39177c3464d1444e1
Author: Qian Hong <qhong@codeweavers.com>
Date:   Thu Oct 29 09:17:46 2015 +0100

    Check for correct funtion entry address in munge_threadfunc
    
    	* init.cc (munge_threadfunc): Check that we're actually replacing
    	the correct original function address on the stack.
    	* ntdll.h (enum _THREADINFOCLASS): Add ThreadQuerySetWin32StartAddress.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/ChangeLog     | 6 ++++++
 winsup/cygwin/init.cc       | 9 +++++++--
 winsup/cygwin/ntdll.h       | 3 ++-
 winsup/cygwin/release/2.3.0 | 3 +++
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index afbe7a2..337a1d2 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,9 @@
+2015-10-29  Qian Hong  <qhong@codeweavers.com>
+
+	* init.cc (munge_threadfunc): Check that we're actually replacing
+	the correct original function address on the stack.
+	* ntdll.h (enum _THREADINFOCLASS): Add ThreadQuerySetWin32StartAddress.
+
 2015-08-21  Jon Turney  <jon.turney@dronecode.org.uk>
 
 	* cygwin-cxx.h: Remove execute permissions.
diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc
index 56d4668..69e66a0 100644
--- a/winsup/cygwin/init.cc
+++ b/winsup/cygwin/init.cc
@@ -55,12 +55,17 @@ munge_threadfunc ()
 
   if (threadfunc_ix[0])
     {
-      char *threadfunc = ebp[threadfunc_ix[0]];
+      char *threadfunc = NULL;
+
+      NtQueryInformationThread (NtCurrentThread (),
+				ThreadQuerySetWin32StartAddress,
+				&threadfunc, sizeof threadfunc, NULL);
       if (!search_for || threadfunc == search_for)
 	{
 	  search_for = NULL;
 	  for (i = 0; threadfunc_ix[i]; i++)
-	    ebp[threadfunc_ix[i]] = (char *) threadfunc_fe;
+	    if (!threadfunc || ebp[threadfunc_ix[i]] == threadfunc)
+	       ebp[threadfunc_ix[i]] = (char *) threadfunc_fe;
 	  TlsSetValue (_my_oldfunc, threadfunc);
 	}
     }
diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h
index 13a131d..050e848 100644
--- a/winsup/cygwin/ntdll.h
+++ b/winsup/cygwin/ntdll.h
@@ -1162,7 +1162,8 @@ typedef enum _THREADINFOCLASS
 {
   ThreadBasicInformation = 0,
   ThreadTimes = 1,
-  ThreadImpersonationToken = 5
+  ThreadImpersonationToken = 5,
+  ThreadQuerySetWin32StartAddress = 9
 } THREADINFOCLASS, *PTHREADINFOCLASS;
 
 /* Checked on 64 bit. */
diff --git a/winsup/cygwin/release/2.3.0 b/winsup/cygwin/release/2.3.0
index 9a44bab..c6f70aa 100644
--- a/winsup/cygwin/release/2.3.0
+++ b/winsup/cygwin/release/2.3.0
@@ -50,3 +50,6 @@ Bug Fixes
 
 - Avoid SEGV when handling SIDs with 0 subauthorities.
   Addresses: https://cygwin.com/ml/cygwin/2015-10/msg00141.html
+
+- Fix a potential SEGV on (at least) Wine.
+  Addresses: https://cygwin.com/ml/cygwin/2015-10/msg00018.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]