From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10583 Path: news.gmane.org!.POSTED!not-for-mail From: Assaf Gordon Newsgroups: gmane.linux.lib.musl.general Subject: possible bug in getdtablesize() ? Date: Wed, 5 Oct 2016 17:56:40 -0400 Message-ID: <261b4d35-9075-8b1f-ccb3-fd5654200ae4@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1475704634 10104 195.159.176.226 (5 Oct 2016 21:57:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 5 Oct 2016 21:57:14 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 To: musl@lists.openwall.com Original-X-From: musl-return-10596-gllmg-musl=m.gmane.org@lists.openwall.com Wed Oct 05 23:57:10 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1bruBL-0000ES-6Y for gllmg-musl@m.gmane.org; Wed, 05 Oct 2016 23:56:55 +0200 Original-Received: (qmail 5723 invoked by uid 550); 5 Oct 2016 21:56:55 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 5694 invoked from network); 5 Oct 2016 21:56:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=KzuFIs2U8/ti8rJ7h04AXhZeOKeP3X26NSPKJ/UkRyY=; b=RkDaENytNRvQBaUROwjti9rarItQAji9CBk2iFKJFUBFHbpJsqRS4XSWJSHCtobjGg MzlpActqNtBLmggMzMPiOTFHZ9skUG7KMF+SaE6B9qyBzu4YfJt52/ZrrYQmv38mXsY2 DD+W0/eVdc4ZRwYiAvznZwTMnXabvIyFZlqLEwG+83E7AHu+zN7r6ael6rVd5wWVVO+2 n6XrYe3xFFuO0AItuaTj94vk49MZmFLiJHeN9/P/jIiIB2uKcUtzjTwqrdlxeE2+UrvR tldRw1Bzt0P+OX9UnxfQ0spQ7AW4Z05JDQ8h0+YATxsh5vvmTb/lxlYOAolOzDDDhng+ 7h8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=KzuFIs2U8/ti8rJ7h04AXhZeOKeP3X26NSPKJ/UkRyY=; b=AHxRB6qhK7tMiQuqftmSDF/J8trvqiPEB5tjr022OihVbL4CyKmEK1xMLCz1HjAaQ/ EZAP2bQr51H9ojFqbXnw2BB9bXSbnXJt6gdqbGNDOHEgZ8klkLBfpLeVRiC9SwboDDs5 R4rEsrKtbosGuB/1mxX6XetU/204S2DuWj75Fr6x/LvGOxYoqhy4OCrVILUIz0x0FPRC iWOxvOt3J/ipFn9v49XpfBlq8bbCRrQbfHetzdlgLhSThRWm+V8Gf5NcGTw01LR7EFkH QgtbzfYn3uUReEYHrkq4VqbeaV67mA60n38TIzwTAWoCSGZFykVTA2yQLVkSBZ+qBiBF rsOw== X-Gm-Message-State: AA6/9RkfZiV4GfcWKif8KpofnWDDq3UDb7pTRafsuXBRYjgIPFp9qHYkQbSDA+BMWePF7w== X-Received: by 10.55.103.69 with SMTP id b66mr11059573qkc.108.1475704601718; Wed, 05 Oct 2016 14:56:41 -0700 (PDT) Xref: news.gmane.org gmane.linux.lib.musl.general:10583 Archived-At: 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 #include #include 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