]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Thread: Don't store pointer to thread_name
authorAdam C. Emerson <aemerson@redhat.com>
Tue, 7 Jul 2020 20:39:57 +0000 (16:39 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Wed, 9 Sep 2020 02:09:40 +0000 (22:09 -0400)
Having Thread::create store a pointer to a string that is passed to
ceph_pthread_setname in Thread::entry_wrapper can lead to using a
pointer in the calling thread's stack that gets freed before use.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/Thread.cc
src/common/Thread.h

index ccee3bc84d90c20d77fc2e3fa8bc8b639c83b5e3..ca8d7a18272de6a82a2045153144ca55560cb363 100644 (file)
@@ -62,8 +62,7 @@ static int _set_affinity(int id)
 Thread::Thread()
   : thread_id(0),
     pid(0),
-    cpuid(-1),
-    thread_name(NULL)
+    cpuid(-1)
 {
 }
 
@@ -84,7 +83,7 @@ void *Thread::entry_wrapper()
   if (pid && cpuid >= 0)
     _set_affinity(cpuid);
 
-  ceph_pthread_setname(pthread_self(), thread_name);
+  ceph_pthread_setname(pthread_self(), thread_name.c_str());
 #ifdef WITH_SEASTAR
   crimson::os::AlienStore::configure_thread_memory();
 #endif
index 0ab65fca52f01a04abcda146393724d62f478985..5242fb5f3075888a5c1c3a307ae68a353d9640a6 100644 (file)
@@ -33,7 +33,7 @@ class Thread {
   pthread_t thread_id;
   pid_t pid;
   int cpuid;
-  const char *thread_name;
+  std::string thread_name;
 
   void *entry_wrapper();