From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129184 invoked by alias); 6 Jun 2018 18:56:59 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 129123 invoked by uid 89); 6 Jun 2018 18:56:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:2165 X-HELO: mx1.redhat.com Subject: Re: [PATCH] Improve DST handling (Bug 23102, Bug 21942, Bug 18018, Bug, 23259, CVE-2011-0536 ). To: Carlos O'Donell , Andreas Schwab Cc: GNU C Library , "Dmitry V. Levin" References: <9cf43cb6-511c-ec6c-9a87-e89a467238d9@redhat.com> <7f17e96d-383d-ead5-deea-1b951513caba@redhat.com> <3850dd4f-331e-8a51-3b6b-35b9729aca84@redhat.com> <0a4966f2-3325-704d-8e25-218c8c9737a2@redhat.com> From: Florian Weimer Message-ID: <55403a0a-11bf-7181-c50e-d6bd4c09f3f4@redhat.com> Date: Wed, 06 Jun 2018 18:56:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <0a4966f2-3325-704d-8e25-218c8c9737a2@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-SW-Source: 2018-06/txt/msg00109.txt.bz2 On 06/06/2018 08:49 PM, Carlos O'Donell wrote: > On 06/06/2018 01:28 PM, Florian Weimer wrote: >> On 06/06/2018 07:10 PM, Carlos O'Donell wrote: >>> On 06/06/2018 12:30 PM, Andreas Schwab wrote: >>>> On Jun 06 2018, Carlos O'Donell wrote: >>>> >>>>> +  /* Find longest valid input sequence.  */ >>>>> +  ilen = 0; >>>>> +  while ((input[ilen] >= 'A' && input[ilen] <= 'Z') >>>>> +     || (input[ilen] >= 'a' && input[ilen] <= 'z') >>>>> +     || (input[ilen] >= '0' && input[ilen] <= '9') >>>>> +     || (input[ilen] == '_')) >>>>> +    ++ilen; >>>>> + >>>>> +  rlen = strlen (ref); >>>>> + >>>>> +  /* Can't be the DST we are looking for.  */ >>>>> +  if (rlen != ilen) >>>>> +    return 0; >>>> >>>> Why do you need that?  Just compare, then check the next character. >>> >>> Are you suggesting that: >>> ~~~ >>> rlen = strlen (ref); >>> >>> /* Can't be the DST we are looking for.  */ >>> if (rlen != ilen) >>>    return 0; >>> ~~~ >>> Can be dropped because we are going to compare the strings anyway? >>> >>> I can do that. >> >> If you compare the lengths first, yo ucan use memcmp. >> >> You could compute the length of ref in an inline wrapper function, so that GCC will turn it into a compile-time constant. > > The memcmp is a good suggestion. > > Like so? > > > - len = 0; > - while (name[len] == str[len] && name[len] != '\0') > - ++len; > + /* Find longest valid input sequence. */ > + ilen = 0; > + while ((input[ilen] >= 'A' && input[ilen] <= 'Z') > + || (input[ilen] >= 'a' && input[ilen] <= 'z') > + || (input[ilen] >= '0' && input[ilen] <= '9') > + || (input[ilen] == '_')) > + ++ilen; > + > + rlen = strlen (ref); > + > + /* Can't be the DST we are looking for. */ > + if (rlen != ilen) > + return 0; > + > + /* Compare the DST (no strncmp this early in startup). */ > + if (memcmp (input, ref, ilen) != 0) > + return 0; Yes, that is what I had in mind. > The inline wrapper seems overkill for the rare is_dst() case > continuing past the strchr for '$'. I have no strong preference either way. Thanks, Florian