[Libguestfs] [nbdkit PATCH v2 5/7] server: Allow longer NBD_OPT

Eric Blake eblake at redhat.com
Sat Sep 28 04:48:47 UTC 2019


Fixes the fact that clients could not request the maximum string
length except with NBD_OPT_EXPORT_LEN.  Updates the testsuite to
match.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 server/protocol-handshake-newstyle.c | 12 +++++++-----
 tests/test-long-name.sh              | 10 ++++------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/server/protocol-handshake-newstyle.c b/server/protocol-handshake-newstyle.c
index 34958360..3b5d144e 100644
--- a/server/protocol-handshake-newstyle.c
+++ b/server/protocol-handshake-newstyle.c
@@ -48,7 +48,7 @@
 #define MAX_NR_OPTIONS 32

 /* Maximum length of any option data (bytes). */
-#define MAX_OPTION_LENGTH 4096
+#define MAX_OPTION_LENGTH (NBD_MAX_STRING * 4)

 /* Receive newstyle options. */
 static int
@@ -255,7 +255,7 @@ negotiate_handshake_newstyle_options (struct connection *conn)
   uint64_t version;
   uint32_t option;
   uint32_t optlen;
-  char data[MAX_OPTION_LENGTH+1];
+  CLEANUP_FREE char *data = NULL;
   struct nbd_export_name_option_reply handshake_finish;
   const char *optname;
   uint64_t exportsize;
@@ -281,6 +281,11 @@ negotiate_handshake_newstyle_options (struct connection *conn)
       nbdkit_error ("client option data too long (%" PRIu32 ")", optlen);
       return -1;
     }
+    data = malloc (optlen + 1); /* Allowing a trailing NUL helps some uses */
+    if (data == NULL) {
+      nbdkit_error ("malloc: %m");
+      return -1;
+    }

     option = be32toh (new_option.option);
     optname = name_of_nbd_opt (option);
@@ -448,9 +453,6 @@ negotiate_handshake_newstyle_options (struct connection *conn)
         /* As with NBD_OPT_EXPORT_NAME we print the export name and
          * save it in the connection.
          */
-        /* FIXME: Our current MAX_OPTION_LENGTH prevents us from receiving
-         * an export name at the full NBD_MAX_STRING length.
-         */
         if (check_export_name (conn, option, &data[4], exportnamelen,
                                optlen - 6, true) == -1)
           return -1;
diff --git a/tests/test-long-name.sh b/tests/test-long-name.sh
index 86aefbaf..f9ebad6e 100755
--- a/tests/test-long-name.sh
+++ b/tests/test-long-name.sh
@@ -84,10 +84,10 @@ nbdkit -U - --mask-handshake=0 null --run 'qemu-io -r -f raw -c quit \

 # Repeat with NBD_OPT_GO.
 nbdkit -U - null --run 'qemu-io -r -f raw -c quit \
-  nbd+unix:///'$name1k$name1k'\?socket=$unixsocket' || fail=1
-# FIXME: Right now, we can't accept full 4k length - this should succeed
+  nbd+unix:///'$name4k'\?socket=$unixsocket' || fail=1
+# See above comment about whether this is testing nbdkit or qemu:
 nbdkit -U - null --run 'qemu-io -r -f raw -c quit \
-  nbd+unix:///'$almost4k'\?socket=$unixsocket' && fail=1
+  nbd+unix:///'a$name4k'\?socket=$unixsocket' && fail=1

 # The rest of this test uses the ‘qemu-nbd --list’ option added in qemu 4.0.
 if ! qemu-nbd --help | grep -sq -- --list; then
@@ -96,8 +96,6 @@ if ! qemu-nbd --help | grep -sq -- --list; then
 fi

 # Test response to NBD_OPT_LIST
-nbdkit -U - -e $almost4k null --run 'qemu-nbd --list -k $unixsocket' || fail=1
-# FIXME: Right now, we can't accept full 4k length - this should succeed
-nbdkit -U - -e $name4k null --run 'qemu-nbd --list -k $unixsocket' && fail=1
+nbdkit -U - -e $name4k null --run 'qemu-nbd --list -k $unixsocket' || fail=1

 exit $fail
-- 
2.21.0




More information about the Libguestfs mailing list