From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20956 invoked by alias); 26 Feb 2014 20:35:36 -0000 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org Received: (qmail 20885 invoked by uid 48); 26 Feb 2014 20:35:30 -0000 From: "kyle at redhat dot com" To: glibc-bugs@sourceware.org Subject: [Bug libc/16640] New: string/strtok.c: undefined behaviour inconsistent between x86 and other generic code Date: Wed, 26 Feb 2014 20:35:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: kyle at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-02/txt/msg00764.txt.bz2 https://sourceware.org/bugzilla/show_bug.cgi?id=16640 Bug ID: 16640 Summary: string/strtok.c: undefined behaviour inconsistent between x86 and other generic code Product: glibc Version: unspecified Status: NEW Severity: minor Priority: P2 Component: libc Assignee: unassigned at sourceware dot org Reporter: kyle at redhat dot com CC: drepper.fsp at gmail dot com Created attachment 7444 --> https://sourceware.org/bugzilla/attachment.cgi?id=7444&action=edit 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... regards, Kyle -- You are receiving this mail because: You are on the CC list for the bug.