[Bug 258360] race between setlocale() and iconv_open() causes segfault

[email protected]
Newsgroups gmane.os.freebsd.devel.threading
Message-ID <[email protected]/bugzilla/>
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=258360

            Bug ID: 258360
           Summary: race between setlocale() and iconv_open() causes
                    segfault
           Product: Base System
           Version: 13.0-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: threads
          Assignee: [email protected]
          Reporter: [email protected]

This was discovered by Dmitry Wagin in PR 258212. I'm able to reproduce the
crash with a very simple program, which simply calls iconv_open() and
setlocale() concurrently:

#include <iconv.h>
#include <pthread.h>
#include <locale.h>

void* iconv_thread(void* arg) {
    iconv_open("UTF-8", "UTF-8");
    return NULL;
}

void* locale_thread(void* arg) {
    setlocale(LC_ALL, "en_US.UTF-8");
    return NULL;
}

int main() {
    pthread_t t1, t2;
    pthread_create(&t1, NULL, iconv_thread, NULL);
    pthread_create(&t2, NULL, locale_thread, NULL);
    pthread_join(t1, NULL);
    pthread_join(t2, NULL);
}

On my machine it has a 7/10 chance of crashing. On another user's machine it
only crashes 1/15, so repeated testing is needed.

The stack can be seen at https://pastebin.com/raw/isvMUDRd

-- 
You are receiving this mail because:
You are the assignee for the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.