From b0e5079b5dc37641741c3ea370376261aa06667f Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Tue, 20 Dec 2016 07:13:25 -0800 Subject: [PATCH] LocalSocketImpl.cpp: Set O_CLOEXEC on received FDs Set O_CLOEXEC on received file descriptors. This prevents FD leakage across an exec boundary. Please see the description of O_CLOEXEC in "man 2 open" for the reasons why this is useful. Test: Device boots and no observed errors. Change-Id: Id0d9c9d71efb25dacb26d5d98d93fc3b72c1b6ae --- core/jni/android_net_LocalSocketImpl.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/jni/android_net_LocalSocketImpl.cpp b/core/jni/android_net_LocalSocketImpl.cpp index d6d431019a6da..37b6df1e3d2c0 100644 --- a/core/jni/android_net_LocalSocketImpl.cpp +++ b/core/jni/android_net_LocalSocketImpl.cpp @@ -202,9 +202,7 @@ static ssize_t socket_read_all(JNIEnv *env, jobject thisJ, int fd, msg.msg_control = cmsgbuf; msg.msg_controllen = sizeof(cmsgbuf); - do { - ret = recvmsg(fd, &msg, MSG_NOSIGNAL); - } while (ret < 0 && errno == EINTR); + ret = TEMP_FAILURE_RETRY(recvmsg(fd, &msg, MSG_NOSIGNAL | MSG_CMSG_CLOEXEC)); if (ret < 0 && errno == EPIPE) { // Treat this as an end of stream