Hi,

I've attached a patch for pthread.cxx to prevent a NULL pointer dereference if pthread_getspecific()/pthread_setspecific() are called by threads which were not created by the pthread subsystem.

Clearly threads which are not created via pthreads should not call the pthread APIs, however if they do so they should fail gracefully. We've seen this happen with an "all-pthread" application because there are actually still a few system threads (e.g. network alarm) which are pure eCos threads.

Cheers,
Kelvin.
? pthread.patch
Index: compat/posix/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/compat/posix/current/ChangeLog,v
retrieving revision 1.56
diff -u -r1.56 ChangeLog
--- compat/posix/current/ChangeLog	25 Mar 2009 08:03:56 -0000	1.56
+++ compat/posix/current/ChangeLog	27 Oct 2009 22:58:23 -0000
@@ -1,3 +1,9 @@
+2009-10-28  Kelvin Lawson  <[email protected]>
+
+	* src/pthread.cxx: Add NULL pointer checks in case various
+	functions are called by threads which were not created via
+	pthreads.
+
 2009-03-25  John Dallaway  <[email protected]>
 
 	* src/signal.cxx (pause): Revert change of 2006-07-18 pending
Index: compat/posix/current/src/pthread.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/compat/posix/current/src/pthread.cxx,v
retrieving revision 1.16
diff -u -r1.16 pthread.cxx
--- compat/posix/current/src/pthread.cxx	29 Jan 2009 17:47:52 -0000	1.16
+++ compat/posix/current/src/pthread.cxx	27 Oct 2009 22:58:24 -0000
@@ -1441,6 +1441,8 @@
         PTHREAD_RETURN(EINVAL);
 
     pthread_info *self = pthread_self_info();
+    if( self == NULL )
+        PTHREAD_RETURN(EINVAL);
 
     if( self->thread_data == NULL )
     {
@@ -1472,6 +1474,8 @@
         PTHREAD_RETURN(NULL);
 
     pthread_info *self = pthread_self_info();
+    if( self == NULL )
+        PTHREAD_RETURN(NULL);
 
     if( self->thread_data == NULL )
         val = NULL;

Reply via email to