On Thu, Nov 18, 2021 at 11:58:27PM +0100, [email protected] wrote:
> From: Martin Wilck <[email protected]>
> 
> If the peer uses libmpathcmd, we can be certain that the first
> 8 bytes are being sent in a single chunk of data. It's overkill
> to try and receive the command length byte-by-byte.
> 
Reviewed-by: Benjamin Marzinski <[email protected]>
> Signed-off-by: Martin Wilck <[email protected]>
> ---
>  multipathd/uxlsnr.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
> index 24db377..6355279 100644
> --- a/multipathd/uxlsnr.c
> +++ b/multipathd/uxlsnr.c
> @@ -441,6 +441,7 @@ static int client_state_machine(struct client *c, struct 
> vectors *vecs,
>               if (!(revents & POLLIN))
>                       return STM_BREAK;
>               if (c->cmd_len == 0) {
> +                     size_t len;
>                       /*
>                        * We got POLLIN; assume that at least the length can
>                        * be read immediately.
> @@ -449,17 +450,17 @@ static int client_state_machine(struct client *c, 
> struct vectors *vecs,
>                       c->expires.tv_sec += uxsock_timeout / 1000;
>                       c->expires.tv_nsec += (uxsock_timeout % 1000) * 1000000;
>                       normalize_timespec(&c->expires);
> -                     n = mpath_recv_reply_len(c->fd, 0);
> -                     if (n == -1) {
> -                             condlog(1, "%s: cli[%d]: failed to receive 
> reply len",
> -                                     __func__, c->fd);
> -                             c->error = -ECONNRESET;
> -                     } else if (n > _MAX_CMD_LEN) {
> -                             condlog(1, "%s: cli[%d]: overlong command (%zd 
> bytes)",
> +                     n = recv(c->fd, &len, sizeof(len), 0);
> +                     if (n < (ssize_t)sizeof(len)) {
> +                             condlog(1, "%s: cli[%d]: failed to receive 
> reply len: %zd",
>                                       __func__, c->fd, n);
>                               c->error = -ECONNRESET;
> +                     } else if (len <= 0 || len > _MAX_CMD_LEN) {
> +                             condlog(1, "%s: cli[%d]: invalid command length 
> (%zu bytes)",
> +                                     __func__, c->fd, len);
> +                             c->error = -ECONNRESET;
>                       } else {
> -                             c->cmd_len = n;
> +                             c->cmd_len = len;
>                               condlog(4, "%s: cli[%d]: connected", __func__, 
> c->fd);
>                       }
>                       /* poll for data */
> -- 
> 2.33.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

Reply via email to