public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "neleai at seznam dot cz" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/16640] string/strtok.c: undefined behaviour inconsistent between x86 and other generic code
Date: Thu, 27 Feb 2014 12:14:00 -0000	[thread overview]
Message-ID: <bug-16640-131-AQV8ffu3Ca@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-16640-131@http.sourceware.org/bugzilla/>

http://sourceware.org/bugzilla/show_bug.cgi?id=16640

--- Comment #2 from Ondrej Bilka <neleai at seznam dot cz> ---
On Thu, Feb 27, 2014 at 06:54:43AM +0000, carlos at redhat dot com wrote:
> https://sourceware.org/bugzilla/show_bug.cgi?id=16640
> 
> Carlos O'Donell <carlos at redhat dot com> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|NEW                         |WAITING
>                  CC|                            |carlos at redhat dot com
> 
> --- Comment #1 from Carlos O'Donell <carlos at redhat dot com> ---
> (In reply to Kyle McMartin from comment #0)
> > Created attachment 7444 [details]
> > make string/strtok match x86
> > 
> > The strtok.S implementations for x86_64 and i386 vary from the generic
> > string/strtok.c version. In the former case, if str == NULL, and the saved
> > string is also NULL, the strtok call returns NULL.
> > 
> > In contrast, the string/strtok.c call proceeds to pass s = olds = NULL to
> > strspn which consequently crashes.
> > 
> > While this behaviour is probably permissible, it results in odd portability
> > issues where the behaviour can't be reproduced on x86_64. As well, the
> > generic versions in the BSD libc I looked at (which appears to date back to
> > 4.3BSD or earlier...) also checks for the (s = olds) == NULL condition and
> > handles it, so we have a bit of precedent here.
> > 
> > Attached is a patch which brings the generic string/strtok.c in-line with
> > i386, x86_64 and BSD. It seems better to do that, rather than suddenly make
> > working code SIGSEGV on x86_64...
> 
> The x86_64 and i386 implementations are wrong, they should also fault.
> 
I looked to implementations and they are outdated, a generic
implementation with sse4_2 strpbrk should be faster here.

I will send patch to remove these once I check performance impact.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


  parent reply	other threads:[~2014-02-27 12:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-26 20:35 [Bug libc/16640] New: " kyle at redhat dot com
2014-02-27  6:54 ` [Bug libc/16640] " carlos at redhat dot com
2014-02-27 12:14   ` Ondřej Bílka
2014-02-27 12:14 ` neleai at seznam dot cz [this message]
2014-02-27 15:00 ` carlos at redhat dot com
2014-02-27 17:19 ` kyle at redhat dot com
2014-02-27 18:44 ` carlos at redhat dot com
2014-02-27 18:48 ` kyle at redhat dot com
2014-06-13  6:45 ` fweimer at redhat dot com
2015-08-27 22:21 ` [Bug string/16640] " jsm28 at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-16640-131-AQV8ffu3Ca@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).