File: 0004-9base-Set-FD_CLOEXEC-correctly-using-F_SETFD-not-F_S.patch

package info (click to toggle)
9base 1%3A6-15
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,536 kB
  • sloc: ansic: 61,060; yacc: 1,991; asm: 1,621; cs: 1,150; perl: 965; makefile: 616; sh: 18; sed: 4
file content (41 lines) | stat: -rw-r--r-- 1,187 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From: Guillem Jover <guillem@hadrons.org>
Date: Tue, 18 Dec 2012 17:25:40 +0100
Subject: 9base: Set FD_CLOEXEC correctly using F_SETFD not F_SETFL

Using that value on F_SETFL is just wrong, and might make the call fail
on some systems, as it's requesting to set an undetermined flag. For
example on GNU/* FD_CLOEXEC has value 1, which matches with O_WRONLY.

This might cause the code to at least leak file descriptors, and at worst
to terminate execution.
---
 lib9/create.c |    2 +-
 lib9/open.c   |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Index: 9base/lib9/create.c
===================================================================
--- 9base.orig/lib9/create.c
+++ 9base/lib9/create.c
@@ -67,7 +67,7 @@ out:
 			}
 		}
 		if(cexec)
-			fcntl(fd, F_SETFL, FD_CLOEXEC);
+			fcntl(fd, F_SETFD, FD_CLOEXEC);
 		if(rclose)
 			remove(path);
 	}
Index: 9base/lib9/open.c
===================================================================
--- 9base.orig/lib9/open.c
+++ 9base/lib9/open.c
@@ -54,7 +54,7 @@ p9open(char *name, int mode)
 			}
 		}
 		if(cexec)
-			fcntl(fd, F_SETFL, FD_CLOEXEC);
+			fcntl(fd, F_SETFD, FD_CLOEXEC);
 		if(rclose)
 			remove(name);
 	}