[Libguestfs] [PATCH] daemon: Limit label lengths (RHBZ#597118).

Richard W.M. Jones rjones at redhat.com
Tue Jun 1 15:20:51 UTC 2010


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
-------------- next part --------------
>From f5f43227870f4a2bedbd92361acdc3ca371a8418 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones at redhat.com>
Date: Tue, 1 Jun 2010 15:50:14 +0100
Subject: [PATCH 1/2] daemon: Limit label lengths (RHBZ#597118).

---
 daemon/ext2.c |   21 +++++++++++++++++++++
 daemon/swap.c |   21 +++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/daemon/ext2.c b/daemon/ext2.c
index 7f9d2e0..b7ce627 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -29,6 +29,9 @@
 #include "c-ctype.h"
 #include "actions.h"
 
+/* Confirmed this is true up to ext4 from the Linux sources. */
+#define EXT2_LABEL_MAX 16
+
 /* Choose which tools like mke2fs to use.  For RHEL 5 (only) there
  * is a special set of tools which support ext2/3/4.  eg. On RHEL 5,
  * mke2fs only supports ext2/3, but mke4fs supports ext2/3/4.
@@ -156,6 +159,12 @@ do_set_e2label (const char *device, const char *label)
   if (e2prog (prog) == -1)
     return -1;
 
+  if (strlen (label) > EXT2_LABEL_MAX) {
+    reply_with_error ("%s: ext2 labels are limited to %d bytes",
+                      label, EXT2_LABEL_MAX);
+    return -1;
+  }
+
   r = command (NULL, &err, prog, device, label, NULL);
   if (r == -1) {
     reply_with_error ("%s", err);
@@ -320,6 +329,12 @@ do_mke2journal_L (int blocksize, const char *label, const char *device)
   if (e2prog (prog) == -1)
     return -1;
 
+  if (strlen (label) > EXT2_LABEL_MAX) {
+    reply_with_error ("%s: ext2 labels are limited to %d bytes",
+                      label, EXT2_LABEL_MAX);
+    return -1;
+  }
+
   char blocksize_s[32];
   snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
 
@@ -406,6 +421,12 @@ do_mke2fs_JL (const char *fstype, int blocksize, const char *device,
   if (e2prog (prog) == -1)
     return -1;
 
+  if (strlen (label) > EXT2_LABEL_MAX) {
+    reply_with_error ("%s: ext2 labels are limited to %d bytes",
+                      label, EXT2_LABEL_MAX);
+    return -1;
+  }
+
   char blocksize_s[32];
   snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
 
diff --git a/daemon/swap.c b/daemon/swap.c
index f22f2de..5de6ba6 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -28,6 +28,9 @@
 #include "actions.h"
 #include "optgroups.h"
 
+/* Confirmed this is true for Linux swap partitions from the Linux sources. */
+#define SWAP_LABEL_MAX 16
+
 /* Convenient place to test for the later version of e2fsprogs
  * and util-linux which supports -U parameters to specify UUIDs.
  * (Not supported in RHEL 5).
@@ -77,6 +80,12 @@ do_mkswap (const char *device)
 int
 do_mkswap_L (const char *label, const char *device)
 {
+  if (strlen (label) > SWAP_LABEL_MAX) {
+    reply_with_error ("%s: Linux swap labels are limited to %d bytes",
+                      label, SWAP_LABEL_MAX);
+    return -1;
+  }
+
   return mkswap (device, "-L", label);
 }
 
@@ -179,12 +188,24 @@ do_swapoff_file (const char *path)
 int
 do_swapon_label (const char *label)
 {
+  if (strlen (label) > SWAP_LABEL_MAX) {
+    reply_with_error ("%s: Linux swap labels are limited to %d bytes",
+                      label, SWAP_LABEL_MAX);
+    return -1;
+  }
+
   return swaponoff ("swapon", "-L", label);
 }
 
 int
 do_swapoff_label (const char *label)
 {
+  if (strlen (label) > SWAP_LABEL_MAX) {
+    reply_with_error ("%s: Linux swap labels are limited to %d bytes",
+                      label, SWAP_LABEL_MAX);
+    return -1;
+  }
+
   return swaponoff ("swapoff", "-L", label);
 }
 
-- 
1.6.6.1



More information about the Libguestfs mailing list