* [PATCH 2/2] lib: Use SOCK_CLOEXEC where needed
@ 2012-12-24 16:44 Cristian Rodríguez
2012-12-24 17:13 ` Marcel Holtmann
0 siblings, 1 reply; 2+ messages in thread
From: Cristian Rodríguez @ 2012-12-24 16:44 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Cristian Rodríguez
Calling programs might fork().. execve() and we will end
up leaking fds.
---
lib/hci.c | 8 ++++----
lib/sdp.c | 13 ++++++-------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/lib/hci.c b/lib/hci.c
index 66b2d5f..1f9058f 100644
--- a/lib/hci.c
+++ b/lib/hci.c
@@ -817,7 +817,7 @@ int hci_for_each_dev(int flag, int (*func)(int dd, int dev_id, long arg),
int dev_id = -1;
int i, sk, err = 0;
- sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ sk = socket(AF_BLUETOOTH, SOCK_RAW|SOCK_CLOEXEC, BTPROTO_HCI);
if (sk < 0)
return -1;
@@ -909,7 +909,7 @@ int hci_devinfo(int dev_id, struct hci_dev_info *di)
{
int dd, err, ret;
- dd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ dd = socket(AF_BLUETOOTH, SOCK_RAW|SOCK_CLOEXEC, BTPROTO_HCI);
if (dd < 0)
return dd;
@@ -965,7 +965,7 @@ int hci_inquiry(int dev_id, int len, int nrsp, const uint8_t *lap,
}
}
- dd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ dd = socket(AF_BLUETOOTH, SOCK_RAW|SOCK_CLOEXEC, BTPROTO_HCI);
if (dd < 0)
return dd;
@@ -1021,7 +1021,7 @@ int hci_open_dev(int dev_id)
int dd, err;
/* Create HCI socket */
- dd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ dd = socket(AF_BLUETOOTH, SOCK_RAW|SOCK_CLOEXEC, BTPROTO_HCI);
if (dd < 0)
return dd;
diff --git a/lib/sdp.c b/lib/sdp.c
index e1e37ed..1ed4304 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -4536,7 +4536,7 @@ static int sdp_connect_local(sdp_session_t *session)
{
struct sockaddr_un sa;
- session->sock = socket(PF_UNIX, SOCK_STREAM, 0);
+ session->sock = socket(PF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
if (session->sock < 0)
return -1;
session->local = 1;
@@ -4553,19 +4553,18 @@ static int sdp_connect_l2cap(const bdaddr_t *src,
uint32_t flags = session->flags;
struct sockaddr_l2 sa;
int sk;
+ int sockflags = SOCK_SEQPACKET | SOCK_CLOEXEC;
+
+ if (flags & SDP_NON_BLOCKING)
+ sockflags |= SOCK_NONBLOCK;
- session->sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
+ session->sock = socket(PF_BLUETOOTH, sockflags, BTPROTO_L2CAP);
if (session->sock < 0)
return -1;
session->local = 0;
sk = session->sock;
- if (flags & SDP_NON_BLOCKING) {
- long arg = fcntl(sk, F_GETFL, 0);
- fcntl(sk, F_SETFL, arg | O_NONBLOCK);
- }
-
memset(&sa, 0, sizeof(sa));
sa.l2_family = AF_BLUETOOTH;
--
1.8.0.2
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 2/2] lib: Use SOCK_CLOEXEC where needed
2012-12-24 16:44 [PATCH 2/2] lib: Use SOCK_CLOEXEC where needed Cristian Rodríguez
@ 2012-12-24 17:13 ` Marcel Holtmann
0 siblings, 0 replies; 2+ messages in thread
From: Marcel Holtmann @ 2012-12-24 17:13 UTC (permalink / raw)
To: Cristian Rodríguez; +Cc: linux-bluetooth
Hi Cristian,
> Calling programs might fork().. execve() and we will end
> up leaking fds.
> ---
> lib/hci.c | 8 ++++----
> lib/sdp.c | 13 ++++++-------
> 2 files changed, 10 insertions(+), 11 deletions(-)
you need to pay more attention to your patches.
Applying: lib: Use SOCK_CLOEXEC where needed
/data/devel/bluez/.git/rebase-apply/patch:64: trailing whitespace.
fatal: 1 line adds whitespace errors.
Patch failed at 0001 lib: Use SOCK_CLOEXEC where needed
I fixed this up now as well.
> diff --git a/lib/hci.c b/lib/hci.c
> index 66b2d5f..1f9058f 100644
> --- a/lib/hci.c
> +++ b/lib/hci.c
> @@ -817,7 +817,7 @@ int hci_for_each_dev(int flag, int (*func)(int dd, int dev_id, long arg),
> int dev_id = -1;
> int i, sk, err = 0;
>
> - sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
> + sk = socket(AF_BLUETOOTH, SOCK_RAW|SOCK_CLOEXEC, BTPROTO_HCI);
This needs an extra space between the socket flags. And so on...
Regards
Marcel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-12-24 17:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-24 16:44 [PATCH 2/2] lib: Use SOCK_CLOEXEC where needed Cristian Rodríguez
2012-12-24 17:13 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox