cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Call-attention-to-truncation-of-long-NBD-expor.patch

ddf19c
From c8ecaea34f03b8ddda7d2b41b0d6f397469c8959 Mon Sep 17 00:00:00 2001
ddf19c
From: Eric Blake <eblake@redhat.com>
ddf19c
Date: Wed, 10 Jun 2020 18:32:02 -0400
ddf19c
Subject: [PATCH 2/2] block: Call attention to truncation of long NBD exports
ddf19c
ddf19c
RH-Author: Eric Blake <eblake@redhat.com>
ddf19c
Message-id: <20200610183202.3780750-3-eblake@redhat.com>
ddf19c
Patchwork-id: 97495
ddf19c
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 2/2] block: Call attention to truncation of long NBD exports
ddf19c
Bugzilla: 1845384
ddf19c
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
ddf19c
Commit 93676c88 relaxed our NBD client code to request export names up
ddf19c
to the NBD protocol maximum of 4096 bytes without NUL terminator, even
ddf19c
though the block layer can't store anything longer than 4096 bytes
ddf19c
including NUL terminator for display to the user.  Since this means
ddf19c
there are some export names where we have to truncate things, we can
ddf19c
at least try to make the truncation a bit more obvious for the user.
ddf19c
Note that in spite of the truncated display name, we can still
ddf19c
communicate with an NBD server using such a long export name; this was
ddf19c
deemed nicer than refusing to even connect to such a server (since the
ddf19c
server may not be under our control, and since determining our actual
ddf19c
length limits gets tricky when nbd://host:port/export and
ddf19c
nbd+unix:///export?socket=/path are themselves variable-length
ddf19c
expansions beyond the export name but count towards the block layer
ddf19c
name length).
ddf19c
ddf19c
Reported-by: Xueqiang Wei <xuwei@redhat.com>
ddf19c
Fixes: https://bugzilla.redhat.com/1843684
ddf19c
Signed-off-by: Eric Blake <eblake@redhat.com>
ddf19c
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
ddf19c
Message-Id: <20200610163741.3745251-3-eblake@redhat.com>
ddf19c
(cherry picked from commit 5c86bdf1208916ece0b87e1151c9b48ee54faa3e)
ddf19c
Signed-off-by: Eric Blake <eblake@redhat.com>
ddf19c
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
ddf19c
---
ddf19c
 block.c     |  7 +++++--
ddf19c
 block/nbd.c | 21 +++++++++++++--------
ddf19c
 2 files changed, 18 insertions(+), 10 deletions(-)
ddf19c
ddf19c
diff --git a/block.c b/block.c
ddf19c
index 12c8941879..57740d312e 100644
ddf19c
--- a/block.c
ddf19c
+++ b/block.c
ddf19c
@@ -6683,8 +6683,11 @@ void bdrv_refresh_filename(BlockDriverState *bs)
ddf19c
         pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename);
ddf19c
     } else {
ddf19c
         QString *json = qobject_to_json(QOBJECT(bs->full_open_options));
ddf19c
-        snprintf(bs->filename, sizeof(bs->filename), "json:%s",
ddf19c
-                 qstring_get_str(json));
ddf19c
+        if (snprintf(bs->filename, sizeof(bs->filename), "json:%s",
ddf19c
+                     qstring_get_str(json)) >= sizeof(bs->filename)) {
ddf19c
+            /* Give user a hint if we truncated things. */
ddf19c
+            strcpy(bs->filename + sizeof(bs->filename) - 4, "...");
ddf19c
+        }
ddf19c
         qobject_unref(json);
ddf19c
     }
ddf19c
 }
ddf19c
diff --git a/block/nbd.c b/block/nbd.c
ddf19c
index 927915d93d..5bb154017d 100644
ddf19c
--- a/block/nbd.c
ddf19c
+++ b/block/nbd.c
ddf19c
@@ -1978,6 +1978,7 @@ static void nbd_refresh_filename(BlockDriverState *bs)
ddf19c
 {
ddf19c
     BDRVNBDState *s = bs->opaque;
ddf19c
     const char *host = NULL, *port = NULL, *path = NULL;
ddf19c
+    size_t len = 0;
ddf19c
 
ddf19c
     if (s->saddr->type == SOCKET_ADDRESS_TYPE_INET) {
ddf19c
         const InetSocketAddress *inet = &s->saddr->u.inet;
ddf19c
@@ -1990,17 +1991,21 @@ static void nbd_refresh_filename(BlockDriverState *bs)
ddf19c
     } /* else can't represent as pseudo-filename */
ddf19c
 
ddf19c
     if (path && s->export) {
ddf19c
-        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
ddf19c
-                 "nbd+unix:///%s?socket=%s", s->export, path);
ddf19c
+        len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
ddf19c
+                       "nbd+unix:///%s?socket=%s", s->export, path);
ddf19c
     } else if (path && !s->export) {
ddf19c
-        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
ddf19c
-                 "nbd+unix://?socket=%s", path);
ddf19c
+        len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
ddf19c
+                       "nbd+unix://?socket=%s", path);
ddf19c
     } else if (host && s->export) {
ddf19c
-        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
ddf19c
-                 "nbd://%s:%s/%s", host, port, s->export);
ddf19c
+        len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
ddf19c
+                       "nbd://%s:%s/%s", host, port, s->export);
ddf19c
     } else if (host && !s->export) {
ddf19c
-        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
ddf19c
-                 "nbd://%s:%s", host, port);
ddf19c
+        len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
ddf19c
+                       "nbd://%s:%s", host, port);
ddf19c
+    }
ddf19c
+    if (len > sizeof(bs->exact_filename)) {
ddf19c
+        /* Name is too long to represent exactly, so leave it empty. */
ddf19c
+        bs->exact_filename[0] = '\0';
ddf19c
     }
ddf19c
 }
ddf19c
 
ddf19c
-- 
ddf19c
2.27.0
ddf19c