X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fswap.c;h=907781449da95a9b23053279fe0cbef22a3074b0;hb=79f5720d2ccab820c90b7516f3fbf5e3dcbe9c8f;hp=f22f2dec16729d441d1ffe12b63e5de41dabf331;hpb=9d158c3ab132df21d58890f18224cd2fe020de67;p=libguestfs.git diff --git a/daemon/swap.c b/daemon/swap.c index f22f2de..9077814 100644 --- a/daemon/swap.c +++ b/daemon/swap.c @@ -23,11 +23,14 @@ #include #include -#include "../src/guestfs_protocol.h" +#include "guestfs_protocol.h" #include "daemon.h" #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); }