public inbox for ecos-patches@sourceware.org
 help / color / mirror / Atom feed
* Pthread NULL pointer dereference
@ 2009-10-28  0:30 Kelvin Lawson
  0 siblings, 0 replies; only message in thread
From: Kelvin Lawson @ 2009-10-28  0:30 UTC (permalink / raw)
  To: ecos-patches

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

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.

[-- Attachment #2: pthread.patch --]
[-- Type: text/x-patch, Size: 1492 bytes --]

? 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  <kelvinl@users.sf.net>
+
+	* 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  <john@dallaway.org.uk>
 
 	* 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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-10-28  0:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-28  0:30 Pthread NULL pointer dereference Kelvin Lawson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).