Bug 239142 - pthread_set_name_np no longer allows NULL to clear the thread name
Summary: pthread_set_name_np no longer allows NULL to clear the thread name
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: threads (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-threads mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-11 12:08 UTC by Lewis Donzis
Modified: 2019-07-14 05:41 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lewis Donzis 2019-07-11 12:08:08 UTC
pthread_set_name_np() previously allowed a NULL pointer to clear the thread name.

In FreeBSD 12.0, the library will dereference the null pointer, leading to a segment violation.

In /usr/src/lib/libthr/thread/thr_info.c, we have:

static void
thr_set_name_np(struct pthread *thread, const char *name)
{

        free(thread->name);
        thread->name = strdup(name);
}

The last line of the function should more correctly be:

        thread->name = name ? strdup(name) : NULL;
Comment 1 commit-hook freebsd_committer 2019-07-11 16:19:43 UTC
A commit references this bug:

Author: kib
Date: Thu Jul 11 16:19:33 UTC 2019
New revision: 349912
URL: https://svnweb.freebsd.org/changeset/base/349912

Log:
  Restore ability to pass NULL name argument to pthread_set_name_np(3)
  to clear the thread name.

  PR:	239142
  Submitted by:	Lewis Donzis <lew@perftech.com>
  MFC after:	3 days

Changes:
  head/lib/libthr/thread/thr_info.c
Comment 2 commit-hook freebsd_committer 2019-07-14 05:39:27 UTC
A commit references this bug:

Author: kib
Date: Sun Jul 14 05:39:03 UTC 2019
New revision: 349982
URL: https://svnweb.freebsd.org/changeset/base/349982

Log:
  MFC r349912:
  Restore ability to pass NULL name argument to pthread_set_name_np(3)
  to clear the thread name.

  PR:	239142

Changes:
_U  stable/12/
  stable/12/lib/libthr/thread/thr_info.c
Comment 3 commit-hook freebsd_committer 2019-07-14 05:41:29 UTC
A commit references this bug:

Author: kib
Date: Sun Jul 14 05:41:14 UTC 2019
New revision: 349984
URL: https://svnweb.freebsd.org/changeset/base/349984

Log:
  MFC r349912:
  Restore ability to pass NULL name argument to pthread_set_name_np(3)
  to clear the thread name.

  PR:	239142

Changes:
_U  stable/11/
  stable/11/lib/libthr/thread/thr_info.c