[Libguestfs] [PATCH] protocol: Ignore rest of option when replying with error

Eric Blake eblake at redhat.com
Fri May 20 14:04:05 UTC 2016


We must consume the payload of any option received, whether or
not we can answer the option successfully, in order to be in
sync for reading the next option.  This is particularly true
once clients start using NBD_OPT_GO, as long as we don't happen
to service that option.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 src/connections.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/connections.c b/src/connections.c
index 0c93f35..840e315 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -334,6 +334,10 @@ _negotiate_handshake_newstyle_options (struct connection *conn)
         if (send_newstyle_option_reply (conn, option, NBD_REP_ERR_INVALID)
             == -1)
           return -1;
+        if (xread (conn->sockin, data, optlen) == -1) {
+          nbdkit_error ("read: %m");
+          return -1;
+        }
         continue;
       }

@@ -351,6 +355,10 @@ _negotiate_handshake_newstyle_options (struct connection *conn)
       /* Unknown option. */
       if (send_newstyle_option_reply (conn, option, NBD_REP_ERR_UNSUP) == -1)
         return -1;
+      if (xread (conn->sockin, data, optlen) == -1) {
+        nbdkit_error ("read: %m");
+        return -1;
+      }
     }

     /* Note, since it's not very clear from the protocol doc, that the
-- 
2.5.5




More information about the Libguestfs mailing list