aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2016-08-16 10:59:40 +0200
committerAndreas Schneider <asn@samba.org>2016-08-23 16:27:48 +0200
commit04dacf2d2e764eb9fd0791642893b4e1bc199ef0 (patch)
treeae1a24906c70d2daad7f83eda63597eba14d5ad7 /src
parent3eee8df6964fdca0d22967a5c8d65f934e935f34 (diff)
downloadsocket_wrapper-04dacf2d2e764eb9fd0791642893b4e1bc199ef0.tar.gz
socket_wrapper-04dacf2d2e764eb9fd0791642893b4e1bc199ef0.tar.xz
socket_wrapper-04dacf2d2e764eb9fd0791642893b4e1bc199ef0.zip
swrap: Treat the case of fd == newfd correctly in dup2()
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src')
-rw-r--r--src/socket_wrapper.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 00518c1..0b13a8c 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5186,6 +5186,16 @@ static int swrap_dup2(int fd, int newfd)
return libc_dup2(fd, newfd);
}
+ if (fd == newfd) {
+ /*
+ * According to the manpage:
+ *
+ * "If oldfd is a valid file descriptor, and newfd has the same
+ * value as oldfd, then dup2() does nothing, and returns newfd."
+ */
+ return newfd;
+ }
+
if (find_socket_info(newfd)) {
/* dup2() does an implicit close of newfd, which we
* need to emulate */