[PATCH] ferror.3: Warn about closing the result of fileno()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since adding checking to Android's bionic for file descriptor double-closes,
we've found that the most common cause of these bugs is incorrect use of
fileno(3). There appears to be a common misconception that it transfers
ownership of the file descriptor to the caller.
---
 man3/ferror.3 | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/man3/ferror.3 b/man3/ferror.3
index b45eb5559..609e10cf8 100644
--- a/man3/ferror.3
+++ b/man3/ferror.3
@@ -89,7 +89,15 @@ The function
 .BR fileno ()
 examines the argument
 .I stream
-and returns its integer file descriptor.
+and returns the integer file descriptor used to implement this stream.
+The file descriptor is still owned by
+.I stream
+and will be closed when
+.BR fclose (3)
+is called.
+Duplicate the file descriptor with
+.BR dup (2)
+before passing it to code that might close it.
 .PP
 For nonlocking counterparts, see
 .BR unlocked_stdio (3).
-- 
2.19.0.605.g01d371f741-goog
From 7be1541bfbb9494614e2ecb7782918bf76548ff6 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <enh@xxxxxxxxxx>
Date: Mon, 1 Oct 2018 10:23:45 -0700
Subject: [PATCH] ferror.3: Warn about closing the result of fileno()

Since adding checking to Android's bionic for file descriptor double-closes,
we've found that the most common cause of these bugs is incorrect use of
fileno(3). There appears to be a common misconception that it transfers
ownership of the file descriptor to the caller.
---
 man3/ferror.3 | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/man3/ferror.3 b/man3/ferror.3
index b45eb5559..609e10cf8 100644
--- a/man3/ferror.3
+++ b/man3/ferror.3
@@ -89,7 +89,15 @@ The function
 .BR fileno ()
 examines the argument
 .I stream
-and returns its integer file descriptor.
+and returns the integer file descriptor used to implement this stream.
+The file descriptor is still owned by
+.I stream
+and will be closed when
+.BR fclose (3)
+is called.
+Duplicate the file descriptor with
+.BR dup (2)
+before passing it to code that might close it.
 .PP
 For nonlocking counterparts, see
 .BR unlocked_stdio (3).
-- 
2.19.0.605.g01d371f741-goog


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux