Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 08 Sep 2021 04:25:07 +0000
From:      bugzilla-noreply@freebsd.org
To:        threads@FreeBSD.org
Subject:   [Bug 258360] race between setlocale() and iconv_open() causes segfault
Message-ID:  <bug-258360-13406@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D258360

            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: threads@FreeBSD.org
          Reporter: henry.hu.sh@gmail.com

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

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-258360-13406>