From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 6873 invoked from network); 9 Jun 2022 20:34:43 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 9 Jun 2022 20:34:43 -0000 Received: (qmail 23560 invoked by uid 550); 9 Jun 2022 20:34:41 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 22501 invoked from network); 9 Jun 2022 20:34:40 -0000 Date: Thu, 9 Jun 2022 16:34:27 -0400 From: Rich Felker To: Hans Harder Cc: musl@lists.openwall.com Message-ID: <20220609203426.GE7074@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] hostname is using a case sensitive search in function name_from_hosts On Thu, Jun 09, 2022 at 08:42:28PM +0200, Hans Harder wrote: > Hi, > I discovered that the function name_from_hosts parses the /etc/hosts > file and does a case sensitive search for a name. > Sometimes I encounter mixed upper and lowercase hostnames in a /etc/hosts file. > It would be easier if the function searches for the name in a case > insensitive way.... > > By changing line 68 in src/network/lookup_name.c > for(p=line+1; (p=strstr(p, name)) && > to: > for(p=line+1; (p=strcasestr(p, name)) && > > That would resolve the problem. strcasestr isn't a good match here, because it's quadratic time and would be potentially quite slow (depending on file contents). It's also not in a usable namespace, and is something of a junk function we included for questionable reasons. The core problem here is that strstr isn't really the right operation to be using, and was something of a lazy hack. Due to the linear-time implementation it doesn't hurt, but it would make a lot more sense to parse this right looking at separators. Even then though it's some work to make it properly case-insensitive; strcasecmp is insufficient and only handles single-byte characters. So the right thing to do is really picking up review and merge of the draft IDN handling work, which (if I'm remembering right) normalizes case as an inherent part of the process. Rich