2013-12-11 11:44:58

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH] android/tester: Fix closing invalid fd

From: Andrei Emeltchenko <[email protected]>

This fixes possible closing invalid fd in a case socket() fails
---
android/android-tester.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index 09c76c9..12d7613 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -357,8 +357,10 @@ static void emulator(int pipe, int hci_index)
ssize_t len;

fd = socket(PF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0);
- if (fd < 0)
- goto failed;
+ if (fd < 0) {
+ close(pipe)
+ return;
+ }

tv.tv_sec = WAIT_FOR_SIGNAL_TIME;
tv.tv_usec = 0;
@@ -374,7 +376,6 @@ static void emulator(int pipe, int hci_index)
}

len = write(pipe, EMULATOR_SIGNAL, sizeof(EMULATOR_SIGNAL));
-
if (len != sizeof(EMULATOR_SIGNAL))
goto failed;

--
1.8.3.2



2013-12-11 12:02:20

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCH] android/tester: Fix closing invalid fd

On Wed, Dec 11, 2013 at 01:44:58PM +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <[email protected]>
>
> This fixes possible closing invalid fd in a case socket() fails
> ---
> android/android-tester.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/android/android-tester.c b/android/android-tester.c
> index 09c76c9..12d7613 100644
> --- a/android/android-tester.c
> +++ b/android/android-tester.c
> @@ -357,8 +357,10 @@ static void emulator(int pipe, int hci_index)
> ssize_t len;
>
> fd = socket(PF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0);
> - if (fd < 0)
> - goto failed;
> + if (fd < 0) {
> + close(pipe)

sorry did not check this missing ;, just apply patches from marcin

Best regards
Andrei Emeltchenko

> + return;
> + }
>
> tv.tv_sec = WAIT_FOR_SIGNAL_TIME;
> tv.tv_usec = 0;
> @@ -374,7 +376,6 @@ static void emulator(int pipe, int hci_index)
> }
>
> len = write(pipe, EMULATOR_SIGNAL, sizeof(EMULATOR_SIGNAL));
> -
> if (len != sizeof(EMULATOR_SIGNAL))
> goto failed;
>
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html