kenballus opened a new issue, #10966:
URL: https://github.com/apache/trafficserver/issues/10966

   EThread derives from Thread, but the Thread constructor does a `static_cast` 
of `this` to `EThread *`:
   ```C++
   Thread::Thread()
   {
     mutex = new_ProxyMutex();
     MUTEX_TAKE_LOCK(mutex, static_cast<EThread *>(this));
     mutex->nthread_holding += THREAD_MUTEX_THREAD_HOLDING;
   }
   ```
   
   Dereferencing a pointer cast from `Thread *` to `EThread *` is UB when the 
underlying object was instantiated as a `Thread`. Since the above cast happens 
in the `Thread` constructor, it is UB.
   
   Here's the UBSan error I get during ATS startup that alerted me to this 
problem:
   ```
   /app/trafficserver/src/iocore/eventsystem/Thread.cc:42:3: runtime error: 
downcast of address 0x7fbd81376800 which does not point to an object of type 
'EThread'
   0x7fbd81376800: note: object is of type 'Thread'
    00 00 00 00  90 89 43 21 3b 56 00 00  00 00 00 00 00 00 00 00  80 8f 00 00 
90 62 00 00  00 00 00 00
                 ^~~~~~~~~~~~~~~~~~~~~~~
                 vptr for 'Thread'
   SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
/app/trafficserver/src/iocore/eventsystem/Thread.cc:42:3 in
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@trafficserver.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to