public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/15589] New: freopen would close oldfd even though oldfd is same as newfd
@ 2013-06-06  5:50 lizhijian at cn dot fujitsu.com
  2013-06-06  5:53 ` [Bug libc/15589] " lizhijian at cn dot fujitsu.com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: lizhijian at cn dot fujitsu.com @ 2013-06-06  5:50 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=15589

            Bug ID: 15589
           Summary: freopen would close oldfd even though oldfd is same as
                    newfd
           Product: glibc
           Version: 2.16
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: lizhijian at cn dot fujitsu.com
                CC: drepper.fsp at gmail dot com

after glibc commit:
http://repo.or.cz/w/glibc.git/commit/94b7cc3711b0b74c1d3ae18b9a2e019e51a8e0bf

It look like cause some problems,
freopen would close oldfd even though oldfd is same as newfd.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/15589] freopen would close oldfd even though oldfd is same as newfd
  2013-06-06  5:50 [Bug libc/15589] New: freopen would close oldfd even though oldfd is same as newfd lizhijian at cn dot fujitsu.com
@ 2013-06-06  5:53 ` lizhijian at cn dot fujitsu.com
  2013-06-06  5:56 ` lizhijian at cn dot fujitsu.com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: lizhijian at cn dot fujitsu.com @ 2013-06-06  5:53 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=15589

--- Comment #1 from lizhijian <lizhijian at cn dot fujitsu.com> ---
A simple C program(freopen-test.c) to reproduce this problem.

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/15589] freopen would close oldfd even though oldfd is same as newfd
  2013-06-06  5:50 [Bug libc/15589] New: freopen would close oldfd even though oldfd is same as newfd lizhijian at cn dot fujitsu.com
  2013-06-06  5:53 ` [Bug libc/15589] " lizhijian at cn dot fujitsu.com
@ 2013-06-06  5:56 ` lizhijian at cn dot fujitsu.com
  2013-06-14  4:03 ` lizhijian at cn dot fujitsu.com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: lizhijian at cn dot fujitsu.com @ 2013-06-06  5:56 UTC (permalink / raw)
  To: glibc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 3011 bytes --]

http://sourceware.org/bugzilla/show_bug.cgi?id=15589

--- Comment #2 from lizhijian <lizhijian at cn dot fujitsu.com> ---

> # ./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)
> 
sorry ,make some miss,forget to create testfile.
# touch file1 file2
test ouput as follows(glibc=2.16):
# ./freopen-test
[S+] close stdin
[S+] stat return error(Bad file descriptor)
[E+] freopen return success, but the newfd was closed

-- 
You are receiving this mail because:
You are on the CC list for the bug.
>From glibc-bugs-return-18859-listarch-glibc-bugs=sources.redhat.com@sourceware.org Thu Jun 06 06:23:44 2013
Return-Path: <glibc-bugs-return-18859-listarch-glibc-bugs=sources.redhat.com@sourceware.org>
Delivered-To: listarch-glibc-bugs@sources.redhat.com
Received: (qmail 26990 invoked by alias); 6 Jun 2013 06:23:44 -0000
Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <glibc-bugs.sourceware.org>
List-Subscribe: <mailto:glibc-bugs-subscribe@sourceware.org>
List-Post: <mailto:glibc-bugs@sourceware.org>
List-Help: <mailto:glibc-bugs-help@sourceware.org>, <http://sourceware.org/lists.html#faqs>
Sender: glibc-bugs-owner@sourceware.org
Delivered-To: mailing list glibc-bugs@sourceware.org
Received: (qmail 26956 invoked by uid 48); 6 Jun 2013 06:23:38 -0000
From: "lizhijian at cn dot fujitsu.com" <sourceware-bugzilla@sourceware.org>
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 06:23: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: attachments.created
Message-ID: <bug-15589-131-jx9C04nWL3@http.sourceware.org/bugzilla/>
In-Reply-To: <bug-15589-131@http.sourceware.org/bugzilla/>
References: <bug-15589-131@http.sourceware.org/bugzilla/>
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/msg00038.txt.bz2
Content-length: 418

http://sourceware.org/bugzilla/show_bug.cgi?id\x15589

--- Comment #3 from lizhijian <lizhijian at cn dot fujitsu.com> ---
Created attachment 7059
  --> http://sourceware.org/bugzilla/attachment.cgi?idp59&actioníit
patch for freopen

When newfd is same as oldfd, __dup3 return -1 and set errno EINVAL
In this case, it don't close oldfd

--
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/15589] freopen would close oldfd even though oldfd is same as newfd
  2013-06-06  5:50 [Bug libc/15589] New: freopen would close oldfd even though oldfd is same as newfd lizhijian at cn dot fujitsu.com
  2013-06-06  5:53 ` [Bug libc/15589] " lizhijian at cn dot fujitsu.com
  2013-06-06  5:56 ` lizhijian at cn dot fujitsu.com
@ 2013-06-14  4:03 ` lizhijian at cn dot fujitsu.com
  2014-06-13 15:10 ` fweimer at redhat dot com
  2015-08-22 20:36 ` [Bug stdio/15589] " jsm28 at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: lizhijian at cn dot fujitsu.com @ 2013-06-14  4:03 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=15589

--- Comment #5 from lizhijian <lizhijian at cn dot fujitsu.com> ---
Created attachment 7079
  --> http://sourceware.org/bugzilla/attachment.cgi?id=7079&action=edit
Fix bugs of freopen

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/15589] freopen would close oldfd even though oldfd is same as newfd
  2013-06-06  5:50 [Bug libc/15589] New: freopen would close oldfd even though oldfd is same as newfd lizhijian at cn dot fujitsu.com
                   ` (2 preceding siblings ...)
  2013-06-14  4:03 ` lizhijian at cn dot fujitsu.com
@ 2014-06-13 15:10 ` fweimer at redhat dot com
  2015-08-22 20:36 ` [Bug stdio/15589] " jsm28 at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 15:10 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15589

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug stdio/15589] freopen would close oldfd even though oldfd is same as newfd
  2013-06-06  5:50 [Bug libc/15589] New: freopen would close oldfd even though oldfd is same as newfd lizhijian at cn dot fujitsu.com
                   ` (3 preceding siblings ...)
  2014-06-13 15:10 ` fweimer at redhat dot com
@ 2015-08-22 20:36 ` jsm28 at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2015-08-22 20:36 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15589

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libc                        |stdio

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-08-22 20:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-06  5:50 [Bug libc/15589] New: freopen would close oldfd even though oldfd is same as newfd lizhijian at cn dot fujitsu.com
2013-06-06  5:53 ` [Bug libc/15589] " lizhijian at cn dot fujitsu.com
2013-06-06  5:56 ` lizhijian at cn dot fujitsu.com
2013-06-14  4:03 ` lizhijian at cn dot fujitsu.com
2014-06-13 15:10 ` fweimer at redhat dot com
2015-08-22 20:36 ` [Bug stdio/15589] " jsm28 at gcc dot gnu.org

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 read-only IMAP folder(s) and NNTP newsgroup(s).