Menu

#195 Invalid thread handle (SEGFAULT)

1.4.0.0
closed
None
2018-05-03
2018-04-18
No

After r1716 I started observing SEGFAULTs in the application I am developing.

A careful code inspection pointed out an issue in the POSIX implementation of vos_thread.c (I don't know about the other platforms): the returned VOS_THREAD_T handle (the first argument of vos_threadCreate()) is a ponter to a struct that is local to the vos_threadCreate() function and that does not exist anymore once the function call returns. So the returned value is a "potentially valid" pointer to "invalid data" (expecially if more than one thread is managed).

I used this pointer with vos_threadIsActive() and the inner call to pthread_kill() caused the SEGFAULT.

One solution could be add the static qualifier to the local structure; but I do not think it is a reasonable solution since the content of the handle would be overwritten each time a new thread is started besides the first one.

Discussion

  • Lorenzo Buzzi

    Lorenzo Buzzi - 2018-04-18

    To be more precise, what I called "a struct that is local to the vos_threadCreate()" is the pthread_t hThread variable.

    Since it is an opaque object I supposed it to be a struct.

    But whether or not it is assignable, at present time it is not returned in the right way.

     
  • Bernd Löhr

    Bernd Löhr - 2018-04-18
    • status: open --> accepted
    • assigned_to: Bernd Löhr
     
  • Bernd Löhr

    Bernd Löhr - 2018-04-18

    Hi Lorenzo,
    the pointer supplied to vos_threadCreate() as pThread must point to a memory area with sizeof(VOS_THREAD_T) – this is not really mentioned in the user manual, sorry!
    And vos_threadCreate() should check for NULL-pointer args, as well.
    Regarding the vos_threadIsActive() function: The change made in r1716 does not do any good. pthread_kill returns the same error as pthread_getscheduleparam on a false or inactive thread.
    It will be reverted.

     
  • Bernd Löhr

    Bernd Löhr - 2018-04-18

    Threads are currently only used by the local test applications. See test/localtest/api_test.c as example. The threadId (type VOS_THREAD_T) is statically allocated in a session structure, and vos_threadCreate gets a pointer to that space...

     
  • Bernd Löhr

    Bernd Löhr - 2018-04-18
    • status: accepted --> pending
     
  • Bernd Löhr

    Bernd Löhr - 2018-04-18

    @Armin: Can you please add a comment in the User Manual about allocation of VOS_THREAD_T before providing a pointer to vos_threadCreate()?

     
  • Bernd Löhr

    Bernd Löhr - 2018-05-02
    • assigned_to: Bernd Löhr --> Armin-Hagen Weiss
     
  • Bernd Löhr

    Bernd Löhr - 2018-05-03
    • status: pending --> closed
     
  • Bernd Löhr

    Bernd Löhr - 2018-05-03

    -> Rev 1724

     

Log in to post a comment.

MongoDB Logo MongoDB