From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: A minor fix in nl-langinfo Date: Wed, 13 Aug 2014 13:22:38 -0400 Message-ID: <87iolwtich.fsf@yeeloong.lan> References: <83mwbdlp9k.fsf@gnu.org> <83wqagjufo.fsf@gnu.org> <87ppg5for4.fsf@gnu.org> <8761hxbdf1.fsf@yeeloong.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1407950646 1366 80.91.229.3 (13 Aug 2014 17:24:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Aug 2014 17:24:06 +0000 (UTC) Cc: guile-devel To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Aug 13 19:23:54 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XHcHB-0005cG-CG for guile-devel@m.gmane.org; Wed, 13 Aug 2014 19:23:53 +0200 Original-Received: from localhost ([::1]:49068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHcHA-0003fw-Qu for guile-devel@m.gmane.org; Wed, 13 Aug 2014 13:23:52 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHcH2-0003Ya-57 for guile-devel@gnu.org; Wed, 13 Aug 2014 13:23:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHcGw-0008Uw-PU for guile-devel@gnu.org; Wed, 13 Aug 2014 13:23:44 -0400 Original-Received: from world.peace.net ([96.39.62.75]:48903) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHcGw-0008Un-MC; Wed, 13 Aug 2014 13:23:38 -0400 Original-Received: from [24.62.95.23] (helo=yeeloong.lan) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1XHcGo-0004WM-Ob; Wed, 13 Aug 2014 13:23:30 -0400 In-Reply-To: <8761hxbdf1.fsf@yeeloong.lan> (Mark H. Weaver's message of "Tue, 12 Aug 2014 17:34:10 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17334 Archived-At: Mark H Weaver writes: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> Eli Zaretskii skribis: >> >>> Sorry, that missed one more instance. Please use this patch instead. >>> >>> --- libguile/i18n.c~0 2014-08-08 17:05:57.262034100 +0300 >>> +++ libguile/i18n.c 2014-08-10 17:20:52.073000000 +0300 >>> @@ -1497,6 +1497,8 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinf >>> { >>> #ifdef USE_GNU_LOCALE_API >>> c_result =3D nl_langinfo_l (c_item, c_locale); >>> + if (c_result !=3D NULL) >>> + c_result =3D strdup (c_result); >>> codeset =3D nl_langinfo_l (CODESET, c_locale); So, I think we have to copy 'codeset' also, because it is not used until after the locale mutex is released, at which point another thread could call 'nl_langinfo*' and overwrite the static buffer that 'codeset' points to. Here's the patch I had in mind. What do you think? Mark --8<---------------cut here---------------start------------->8--- diff --git a/libguile/i18n.c b/libguile/i18n.c index e38e560..411f38a 100644 --- a/libguile/i18n.c +++ b/libguile/i18n.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Softw= are Foundation, Inc. +/* Copyright (C) 2006-2014 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -1465,6 +1465,13 @@ SCM_DEFINE (scm_locale_string_to_inexact, "locale-st= ring->inexact", Note: We don't use Gnulib's `nl_langinfo' module because it's currently= not as complete as the compatibility hacks in `i18n.scm'. */ =20 +static char * +copy_string_or_null (char *s) +{ + if (s !=3D NULL) + s =3D strdup (s); + return s; +} =20 SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0, (SCM item, SCM locale), @@ -1496,8 +1503,8 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0, if (c_locale !=3D NULL) { #ifdef USE_GNU_LOCALE_API - c_result =3D nl_langinfo_l (c_item, c_locale); - codeset =3D nl_langinfo_l (CODESET, c_locale); + c_result =3D copy_string_or_null (nl_langinfo_l (c_item, c_locale)); + codeset =3D copy_string_or_null (nl_langinfo_l (CODESET, c_locale)); #else /* !USE_GNU_LOCALE_API */ /* We can't use `RUN_IN_LOCALE_SECTION ()' here because the locale mutex is already taken. */ @@ -1521,8 +1528,8 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0, scm_locale_error (FUNC_NAME, lsec_err); else { - c_result =3D nl_langinfo (c_item); - codeset =3D nl_langinfo (CODESET); + c_result =3D copy_string_or_null (nl_langinfo (c_item)); + codeset =3D copy_string_or_null (nl_langinfo (CODESET)); =20 restore_locale_settings (&lsec_prev_locale); free_locale_settings (&lsec_prev_locale); @@ -1531,13 +1538,10 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0, } else { - c_result =3D nl_langinfo (c_item); - codeset =3D nl_langinfo (CODESET); + c_result =3D copy_string_or_null (nl_langinfo (c_item)); + codeset =3D copy_string_or_null (nl_langinfo (CODESET)); } =20 - if (c_result !=3D NULL) - c_result =3D strdup (c_result); - unlock_locale_mutex (); =20 if (c_result =3D=3D NULL) @@ -1669,6 +1673,9 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0, } } =20 + if (codeset !=3D NULL) + free (codeset); + return result; } #undef FUNC_NAME --8<---------------cut here---------------end--------------->8---