From: Assaf Gordon <assafgordon@gmail.com>
To: musl@lists.openwall.com
Subject: possible bug in getdtablesize() ?
Date: Wed, 5 Oct 2016 17:56:40 -0400 [thread overview]
Message-ID: <261b4d35-9075-8b1f-ccb3-fd5654200ae4@gmail.com> (raw)
Hello,
It seems that musl's getdtablesize() returns incorrect value,
possibly using the "rlim_max" instead of "rlim_cur" value (just a guess, not sure about the actual reason).
The following code demonstrates: trying to use dup2(2) on a file-descriptor value that "should work".
#include <unistd.h>
#include <stdio.h>
#include <err.h>
int main(void)
{
int fd = STDIN_FILENO;
int maxfd = getdtablesize();
printf("maxfd = %d\n", maxfd);
int newfd = maxfd-1;
int i = dup2(fd,newfd);
if (i == -1)
err(1,"dup2(%d, %d) failed", fd, newfd);
if (i != newfd)
errx(1,"dup2(%d, %d) returned %d", fd, newfd, i);
return 0;
}
With glibc, it works:
$ gcc -o dup2-glibc dup2-test.c
$ strace -e prlimit64,getrlimit,dup2 ./dup2-glibc
getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=4*1024}) = 0
maxfd = 1024
dup2(0, 1023) = 1023
+++ exited with 0 +++
With musl-1.1.15, it failsdue to wrong 'max-fd' value:
$ musl-gcc -o dup2-musl dup2-test.c
$ strace -e prlimit64,getrlimit,dup2 ./dup2-musl
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=4*1024}) = 0
maxfd = 4096
dup2(0, 4095) = -1 EBADF (Bad file descriptor)
dup2-musl: dup2(0, 4095) failed: Bad file descriptor
+++ exited with 1 +++
Using:
$ uname -svr
Linux 3.13.0-88-generic #135-Ubuntu SMP Wed Jun 8 21:10:42 UTC 2016
$ gcc --version
gcc (GCC) 5.2.0
$ ulimit -a
[...]
open files (-n) 1024
and glibc-2.19.
regards,
- assaf
next reply other threads:[~2016-10-05 21:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-05 21:56 Assaf Gordon [this message]
2016-10-05 23:00 ` Rich Felker
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=261b4d35-9075-8b1f-ccb3-fd5654200ae4@gmail.com \
--to=assafgordon@gmail.com \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).