From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12613 invoked by alias); 6 Jun 2013 05:53:08 -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 12578 invoked by uid 48); 6 Jun 2013 05:53:04 -0000 From: "lizhijian at cn dot fujitsu.com" To: glibc-bugs@sourceware.org Subject: [Bug libc/15589] freopen would close oldfd even though oldfd is same as newfd Date: Thu, 06 Jun 2013 05:53:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: 2.16 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lizhijian at cn dot fujitsu.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: Message-ID: In-Reply-To: References: 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: 2013-06/txt/msg00036.txt.bz2 http://sourceware.org/bugzilla/show_bug.cgi?id=15589 --- Comment #1 from lizhijian --- A simple C program(freopen-test.c) to reproduce this problem. #include #include #include #include int main(void) { char *file1 = "./file1"; char *file2 = "./file2"; FILE *fp1, *fp2; struct stat stat_buf; if((fp1 = freopen(file1, "r", stdin)) == NULL) printf("[E+] freopen error(%s)\n", strerror(errno)); if (fstat(fileno(stdin), &stat_buf) == 0) { printf("[S+] close stdin\n"); close(0); //close stdin } if (fstat(fileno(stdin), &stat_buf) == -1) { printf("[S+] stat return error(%s)\n", strerror(errno)); if ((fp2 = freopen(file2, "r", stdin)) == NULL) { printf("[E+] freopen return error(%s)\n",strerror(errno)); return -1; } } if (fstat(fileno(fp2), &stat_buf) == -1) { printf("[E+] freopen return success, but the newfd was closed\n"); return -1; } fclose(fp1); fclose(fp2); printf("[S+] freopen test PASS\n"); } ------------------------ # gcc freopen-test.c -o freopen-test # touch file1 file2 # ./freopen-test [E+] freopen error(No such file or directory) [S+] stat return error(Bad file descriptor) [E+] freopen return error(No such file or directory) # rpm -q glibc glibc-2.16-29.el7.x86_64 -- You are receiving this mail because: You are on the CC list for the bug.