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.133.124]) by sourceware.org (Postfix) with ESMTPS id BA50F3858C83 for ; Mon, 28 Feb 2022 12:04:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BA50F3858C83 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=1646049854; 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=Gu2F7DMib6S/K1283iOwWgBHjo59GsOpD37/vJXCLfU=; b=KOzXOyxK2LMqy4JUTKnUsp8P4DR3ALJSkRH0p72t7YsGG6gjrlUR9Cnpzd9yWGzLPBz5i4 DM2bjNNKOOCKU8QpXFAHJwMtL4VzBDjCdi/iYCu8FLqdizquuh6RE+JOwfUpQf2uVwqXg6 tO/WX6pcgeM0HeX+RmRsFihJWNvCP9s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-s6xrr3jaMYmHRTkLk71r-Q-1; Mon, 28 Feb 2022 07:04:11 -0500 X-MC-Unique: s6xrr3jaMYmHRTkLk71r-Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F431180A08E for ; Mon, 28 Feb 2022 12:04:10 +0000 (UTC) Received: from calimero.vinschen.de (unknown [10.36.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30614104A9FD for ; Mon, 28 Feb 2022 12:04:10 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id A6E96A80CE4; Mon, 28 Feb 2022 13:04:08 +0100 (CET) Date: Mon, 28 Feb 2022 13:04:08 +0100 From: Corinna Vinschen To: newlib@sourceware.org Subject: Re: [PATCH 2/2] newlib/libc/time/tzset_r.c(_tzset_unlocked_r): POSIX angle bracket <> support Message-ID: Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org References: <20220225163959.48753-1-Brian.Inglis@SystematicSW.ab.ca> <20220225163959.48753-3-Brian.Inglis@SystematicSW.ab.ca> MIME-Version: 1.0 In-Reply-To: <20220225163959.48753-3-Brian.Inglis@SystematicSW.ab.ca> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vinschen@redhat.com 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.4 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, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 28 Feb 2022 12:04:18 -0000 Hi Brian, On Feb 25 09:39, Brian Inglis wrote: > > define POSIX specified minimum TZ abbr size 3 TZNAME_MIN > use limits.h TZNAME_MAX, _POSIX_TZNAME_MAX, unistd.h sysconf(_SC_TZNAME_MAX) > issue error if no symbols defined (document fallback value in case required) > allow POSIX angle bracket < > quoted signed alphanumeric tz abbr e.g. > allow POSIX unquoted alphabetic tz abbr e.g. MESZ > apply same changes for DST tz abbr > --- > newlib/libc/time/tzset_r.c | 74 ++++++++++++++++++++++++++++++++------ > 1 file changed, 64 insertions(+), 10 deletions(-) > > diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c > index 9e0cf834bd6b..6a5fd578c0be 100644 > --- a/newlib/libc/time/tzset_r.c > +++ b/newlib/libc/time/tzset_r.c > @@ -1,14 +1,30 @@ > #include <_ansi.h> > +#include /* {,_POSIX_}TZNAME_MAX */ > #include > #include > #include > #include > +#include /* sysconf(_SC_TZNAME_MAX) */ > #include > #include > #include "local.h" > > #define sscanf siscanf /* avoid to pull in FP functions. */ > > +#define TZNAME_MIN 3 /* POSIX specified minimum TZ abbr size */ Are you sure? > +/* TZNAME_MAX - POSIX specified maximum TZ abbr size */ > +/* define TZNAME_MAX if undefined and available */ > +#if !defined(TZNAME_MAX) > +#if defined(_POSIX_TZNAME_MAX) > +#define TZNAME_MAX _POSIX_TZNAME_MAX /* use POSIX value */ > +#elif defined(_SC_TZNAME_MAX) > +#define TZNAME_MAX sysconf(_SC_TZNAME_MAX) /* use sysconf value */ This is not a safe bet. _SC_TZNAME_MAX is defined in unistd.h unconditionally, even for targets not providing sysconf(). And given that _POSIX_TZNAME_MAX is only defined for RTEMS and Cygwin, this will run into problems on most other targets. Only Phoenix-RTOS, RISCV, RTEMS and Cygwin support sysconf, and none of them actually supports _SC_TZNAME_MAX as parameter. And even Cygwin returns -1 and sets errno to EINVAL. Given you're checking _POSIX_TZNAME_MAX first, which is defined on Cygwin, the sysconf path will never be used there anyway. But that's actually a minor point. The real problem is, you can't use sysconf(_SC_TZNAME_MAX) like this: - You don't know at compile time if the function is really supported. - You don't know if _SC_TZNAME_MAX returns a positive value or -1. And then again, there's no good reason to check against _POSIX_TZNAME_MAX either. _POSIX_TZNAME_MAX is a system-independent definition, defining a *minimum* value which has to be supported by the OS. So any OS can define TZNAME_MAX as _POSIX_TZNAME_MAX, or any bigger value, or not at all, if there just is no limit. So, either the system defines TZNAME_MAX, or the system provides sysconf() *and* sysconf(_SC_TZNAME_MAX) returns a positive value. In these cases, a check against that value makes sense. In all other cases, there's just no limit to check for. Corinna