Bug 5605 - dirfd() SEGVs when passed NULL
Summary: dirfd() SEGVs when passed NULL
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-13 15:20 UTC by Steve Peters
Modified: 2014-07-02 07:50 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Peters 2008-01-13 15:20:52 UTC
The following example program SEGVs in dirfd() in libc.  Based on the manpage, it should be returning 
-1.

#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>

int
main() {
    int fd = dirfd(NULL);
}
Comment 1 Andreas Schwab 2008-01-13 15:59:13 UTC
The argument must be a pointer to a valid directory stream.
Comment 2 Steve Peters 2008-01-14 03:13:04 UTC
(In reply to comment #1)
> The argument must be a pointer to a valid directory stream.

...and if it isn't libc should SEGV.  That seems very illogical.  It would seem to make much more sense to 
return -1 and set errno to EBADF.
Comment 3 Roland McGrath 2008-01-14 03:17:11 UTC
You are mistaken in your expectation.  Crashing is the very best thing to do and
this is widely accepted.   Do not reopen a bug for this behavior.  Please seek
advice on best practices for C interfaces elsewhere.  This facility is for bugs
in glibc.  This is not one.