Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 9 Jun 2022 16:34:27 -0400
From: Rich Felker <>
To: Hans Harder <>
Subject: Re: hostname is using a case sensitive search in function

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.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.