Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 16 Jul 2023 21:33:16 +0200
From: Markus Wichmann <nullplan@....net>
To: musl@...ts.openwall.com
Subject: Re: strcmp() guarantees and assumptions

Am Sun, Jul 16, 2023 at 07:59:57PM +0200 schrieb Robert Clausecker:
> That's good to hear.  Any idea on the “what do existing libc
> implementations permit” bit?
>

So I quickly checked musl, dietlibc, bionic, and glibc, and
unsurprisingly, all of the implementations I looked at allow the strings
to be unterminated if they mismatch before access becomes restricted.
This is, of course, an implementation detail that applications must not
rely on, but it nevertheless is the case.

The problem in your implementation is that the calls to strlen() will
iterate over both input strings to the end, causing basically a cache
flush for large inputs, only to then iterate over both inputs a second
time. Iterating only once is a major benefit, since it avoids half of
the cache misses.

Also, glibc already has an SSE strcmp implementation you may want to
look at.

Ciao,
Markus

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.