From nobody Fri May 3 02:15:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1497810100381231.33632037976588; Sun, 18 Jun 2017 11:21:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E97BA4E35B; Sun, 18 Jun 2017 18:21:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8BC375C46E; Sun, 18 Jun 2017 18:21:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BE73C1841C40; Sun, 18 Jun 2017 18:21:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5IIKLdT002295 for ; Sun, 18 Jun 2017 14:20:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id D11BC17DA3; Sun, 18 Jun 2017 18:20:21 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC09C17C75 for ; Sun, 18 Jun 2017 18:20:20 +0000 (UTC) Received: from mail-ua0-f195.google.com (mail-ua0-f195.google.com [209.85.217.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CBE86C057FA1 for ; Sun, 18 Jun 2017 18:20:18 +0000 (UTC) Received: by mail-ua0-f195.google.com with SMTP id d45so1178732uai.1 for ; Sun, 18 Jun 2017 11:20:18 -0700 (PDT) Received: from localhost.localdomain ([191.19.112.219]) by smtp.googlemail.com with ESMTPSA id 75sm2817265vkp.33.2017.06.18.11.20.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Jun 2017 11:20:16 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E97BA4E35B Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E97BA4E35B Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kglCibi2" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CBE86C057FA1 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcfaracco@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CBE86C057FA1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=kjZEiKFw7B5MN5ivbFx5MoanMPJfx1cPFM4dgrCOFrg=; b=kglCibi26Ynz61IiIZo3E/0NO01XlpNHxZvhyKJVMs0n0wp1/es3R3xaCt4thyn8wj tSRyoXQxGBK7qLn+AOrzlmJI0H5MJVctAnEkGZYNZgsP2bl4q/29nL7P2xg/zdGrWR+h a+g2vRcRl1dGv4QFEyp0EZPLBqz+GWlQECmploM8ESmQlwnz3FT1eRKiCFddrgCj4hfC /PL4yuUOMZj2posZaUa5PzbHlEqtk6Mpe7FUMe0RL4bOZXcSsbvItmFySoiiZahi1KTH DfjheTavQ7H0EGtHQWShhISgRFyu7Vk5B1TpXKyd7wRSuENhK0jEzr7t68q4V0+CsGkA 5AvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=kjZEiKFw7B5MN5ivbFx5MoanMPJfx1cPFM4dgrCOFrg=; b=fzZKsHEQVIz30dvC0oQ1Mcq64rZNcRDTtFL0S2TQ6F06whSOA+mPWHHmy2t50xlh7J G82Ji8XuSwWEUV/giHwa0TXyUKHGx/rgTePhlPQIKToJIyfSzxWA3GIbiSVva9m5sMKe 8B3OB4QMj2N79dqBvBFJ1uMIGyZKzDDvWvji/GZfhkw0iYjjrj+9M9SKwjwOGBicvAC7 jF7IoXn5Vw5DL8vMti8jy5G+hRYEFF4SMAhR8jjVhqZ7PjyB8/W20BfZXgpFpAw9+Cor YPXPk3qeeBGSN9ePB0dIuTF6RUi2HSgjPDTSjTrVsALaK6AQCS+n3VZKt5dADf0ytrsO IJFw== X-Gm-Message-State: AKS2vOzh5IVWWPGlxTqsioc3+rpkh68irfMX6gcKJDDGntjZArpxwzpO Ln7NNivDvOVg0ARZy2ZRdA== X-Received: by 10.159.60.162 with SMTP id s34mr12397739uai.89.1497810017920; Sun, 18 Jun 2017 11:20:17 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 18 Jun 2017 15:20:11 -0300 Message-Id: <1497810011-25388-1-git-send-email-jcfaracco@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 18 Jun 2017 18:20:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 18 Jun 2017 18:20:19 +0000 (UTC) for IP:'209.85.217.195' DOMAIN:'mail-ua0-f195.google.com' HELO:'mail-ua0-f195.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.67 (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.217.195 mail-ua0-f195.google.com 209.85.217.195 mail-ua0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] util: fix locale problem with virStrToDouble(). X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sun, 18 Jun 2017 18:21:38 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This commit fixes a locale problem with locales that use comma as a mantissa separator. Example: 12.34 en_US =3D 12,34 pt_BR. Since strtod() is a non-sa= fe function, virStrToDouble() will have problems to parse double numbers from kernel settings and other double numbers from static files (XMLs, JSONs, et= c). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1457634 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1457481 Signed-off-by: Julio Faracco --- src/util/virstring.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 089b539..6dd5138 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -28,6 +28,7 @@ #include "base64.h" #include "c-ctype.h" #include "virstring.h" +#include "virthread.h" #include "viralloc.h" #include "virbuffer.h" #include "virerror.h" @@ -516,6 +517,22 @@ virStrToLong_ullp(char const *s, char **end_ptr, int b= ase, return 0; } =20 +#if HAVE_NEWLOCALE + +static locale_t virLocale; + +static int +virLocaleOnceInit(void) +{ + virLocale =3D newlocale(LC_ALL_MASK, "C", (locale_t)0); + if (!virLocale) + return -1; + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virLocale); +#endif + int virStrToDouble(char const *s, char **end_ptr, @@ -526,7 +543,17 @@ virStrToDouble(char const *s, int err; =20 errno =3D 0; +#if HAVE_NEWLOCALE + locale_t old_loc; + if (virLocaleInitialize() < 0) + return -1; + + old_loc =3D uselocale(virLocale); +#endif val =3D strtod(s, &p); /* exempt from syntax-check */ +#if HAVE_NEWLOCALE + uselocale(old_loc); +#endif err =3D (errno || (!end_ptr && *p) || p =3D=3D s); if (end_ptr) *end_ptr =3D p; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list