[PATCH v2 03/10] raop: Fix loop searching for port number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06.03.2017 08:43, Peter Meerwald-Stadler wrote:
> do...while not reachable, loop should try different ports in case EADDRINUSE is returned
> Coverity ID: #1398161
>
> Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
> ---
>   src/modules/raop/raop-client.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
> index 94342d2..e39663d 100644
> --- a/src/modules/raop/raop-client.c
> +++ b/src/modules/raop/raop-client.c
> @@ -799,13 +799,16 @@ static int open_bind_udp_socket(pa_raop_client *c, uint16_t *actual_port) {
>       }
>   
>       do {
> -        *sa_port = htons(port);
> +        int ret;
>   
> -        if (bind(fd, sa, salen) < 0 && errno != EADDRINUSE) {
> -            pa_log("bind_socket() failed: %s", pa_cstrerror(errno));
> +        *sa_port = htons(port);
> +        ret = bind(fd, sa, salen);
> +        if (!ret)
> +            break;
> +        if (ret < 0 && errno != EADDRINUSE) {
> +            pa_log("bind() failed: %s", pa_cstrerror(errno));
>               goto fail;
>           }
> -        break;
>       } while (++port > 0);
>   

You should also fail if port is 0 after the loop.

>       pa_log_debug("Socket bound to port %d (SOCK_DGRAM)", port);




[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux