X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEF893856965
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1660239372;
	bh=svOg4EALpbs74EbOrnd9bFazJqHzvfYwxWHLaRVWWBI=;
	h=Date:From:To:Subject:References:In-Reply-To:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 Reply-To:From;
	b=sqLA/gVolhaMBhfQtfKCqjDxrPAYSsK3sxnmM2Bjf1mDzWLVHK+MTqgu4bIxcUOJl
	 EV7nNfVolhqSx81jfErGXMCVctw+EtFXPhB5DAfrDAR0nJcI/XUgwaiKzNMiHjU1jP
	 aEsq4qwWwjps78MPb0pN/nOVbKw9QeUdV+3pQS+w=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 468653856DD2
Authentication-Results: sourceware.org;
 dmarc=fail (p=none dis=none) header.from=cygwin.com
Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=cygwin.com
Date: Thu, 11 Aug 2022 19:35:39 +0200
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com, newlib@sourceware.org
Subject: Re: crash in newlocale()
Message-ID: <YvU960nGyeuJUAPt@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com, newlib@sourceware.org
References: <YvRbeAzxwtYwhkkE@venus.tony.develop-help.com>
 <20220811211806.bc7f5426ce52f57d1c1538c2@nifty.ne.jp>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <20220811211806.bc7f5426ce52f57d1c1538c2@nifty.ne.jp>
X-Provags-ID: V03:K1:rMjqZXw3O3FzLOjWgEXilK1xav4uDyu/CXDerr+RlU8128naFSD
 4A9Pa++kqtUb/7hPVjb1aER/hlFAgN2ehIb8/Kk/EsAlkxlsXYkUjMi4+ucVBSBxt6ItWIe
 itxfUZKm4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N_DNSWL_NONE,
 RCVD_IN_MSPIKE_H2, SPF_FAIL, SPF_HELO_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: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Reply-To: cygwin@cygwin.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

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?


Thanks,
Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
