From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BFA55385AC2E for ; Thu, 11 Aug 2022 17:39:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BFA55385AC2E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660239563; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=cOaAUp0/JM8ToajapBrqhpbMjcs+lXC1LkL60RlB8R8=; b=WDWGPWSTH0su2gI7S97wbbksnFe9YFtHR5ysB2q5qnwbLiqray/eaECv5AHNPS3d342qYZ nuaQ5rT3aYm9cMr1tn9j6xNYoQI6ft6tx7MxXnbbk1L+DpJRtE/jQcVKiPZ9VMJvIX6YIb Y8Z8Phr19kAJ/TlZcxMX0u7YF9wwVjM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-KeKZlFaKOAKyG9lOHHqnuQ-1; Thu, 11 Aug 2022 13:39:21 -0400 X-MC-Unique: KeKZlFaKOAKyG9lOHHqnuQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F349F3C106A7 for ; Thu, 11 Aug 2022 17:39:20 +0000 (UTC) Received: from calimero.vinschen.de (unknown [10.39.193.176]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF77F112131B for ; Thu, 11 Aug 2022 17:39:20 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id A47A2A80862; Thu, 11 Aug 2022 19:39:19 +0200 (CEST) Date: Thu, 11 Aug 2022 19:39:19 +0200 From: Corinna Vinschen To: newlib@sourceware.org Subject: Re: crash in newlocale() Message-ID: Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org References: <20220811211806.bc7f5426ce52f57d1c1538c2@nifty.ne.jp> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Aug 2022 17:39:24 -0000 On Aug 11 19:35, Corinna Vinschen wrote: > On Aug 11 21:18, Takashi Yano wrote: > > On Thu, 11 Aug 2022 11:29:28 +1000 > > Tony Cook wrote: > > > Hello everyone, > > > > > > While tracking down a crash in development versions of perl the boostrap > > > miniperl executable was crashing early in the build process: > > > [...] > > > > I looked into this problem and found the access violation > > occurs at: > > newlib/libc/locale/newlocale.c > > @@ 188,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale, > > if (tmp_locale.lc_cat[i].buf == (const void *) -1) > > { > > tmp_locale.lc_cat[i].buf = base->lc_cat[i].buf; > > base->lc_cat[i].ptr = base->lc_cat[i].buf = NULL; <-- Here!!! > > } > > #endif /* __HAVE_LOCALE_INFO__ */ > > _freelocale_r (p, base); > > > > This is because > > locale_t st = newlocale(LC_ALL_MASK, "C", (locale_t)0); > > returns > > extern const struct __locale_t __C_locale; > > return (struct __locale_t *) &__C_locale; > > , which is in the const area that cannot be modified. > > > > This seems to be a newlib bug. > > > > I also found following patch solves the issue. > > > > diff --git a/newlib/libc/locale/newlocale.c b/newlib/libc/locale/newlocale.c > > index 0789d5fd9..1974665ec 100644 > > --- a/newlib/libc/locale/newlocale.c > > +++ b/newlib/libc/locale/newlocale.c > > @@ -108,10 +108,12 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale, > > } > > /* If the new locale is supposed to be all default locale, just return > > a pointer to the default locale. */ > > +#if 0 > > if ((!base && category_mask == 0) > > || (category_mask == LC_VALID_MASK > > && (!strcmp (locale, "C") || !strcmp (locale, "POSIX")))) > > return __get_C_locale (); > > +#endif > > /* Start with setting all values to the default locale values. */ > > tmp_locale = *__get_C_locale (); > > /* Fill out new category strings. */ > > I think the right thing to do is to avoid freeing this data, if the base > locale is the C locale. I sent a patch to cygwin-patches for review. > Can you please take a look? Resent to the newlib list where it belongs, d'oh. Corinna