Bug 1018323 - strdup(3) segfaults when passing NULL to it
Summary: strdup(3) segfaults when passing NULL to it
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 19
Hardware: All
OS: Linux
high
high
Target Milestone: ---
Assignee: Carlos O'Donell
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1018326 1018331
TreeView+ depends on / blocked
 
Reported: 2013-10-11 17:22 UTC by Eryu Guan
Modified: 2016-11-24 16:11 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1018326 1018331 (view as bug list)
Environment:
Last Closed: 2013-10-11 19:01:21 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Eryu Guan 2013-10-11 17:22:54 UTC
Description of problem:
$ cat strduptest.c 
#include <string.h>

int main(void)
{
        strdup(NULL);
}

$ gcc -o strduptest strduptest.c
$ ./strduptest
Segmentation fault (core dumped)

And dmesg shows:
strduptest[2374]: segfault at 0 ip 0000003b97086711 sp 00007fff67a8cd98 error 4 in libc-2.17.so[3b97000000+1b6000]

Version-Release number of selected component (if applicable):
glibc-2.17-18.fc19

How reproducible:
always

Steps to Reproduce:
1. see description
2.
3.

Actual results:
segfault

Expected results:
strdup(3) should deal with NULL correctly

Additional info:

Comment 1 Jakub Jelinek 2013-10-11 19:01:21 UTC
Why do you think it is wrong?  NULL is not a pointer to a valid string, so it is your bug to call it with that.  See
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strdup.html


Note You need to log in before you can comment on or make changes to this bug.