X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fext2.c;h=725352e3ff0ed32eea07de43d2fcdeb4ede8819a;hp=3a075e565dbd42cd0f853a47d158359a4329a880;hb=428a45c3e15f03e9861e1b551e1ae8da821dba5f;hpb=71b02d6654395ff04689055f3820b3ad4e54ec00 diff --git a/daemon/ext2.c b/daemon/ext2.c index 3a075e5..725352e 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -24,11 +24,14 @@ #include #include -#include "../src/guestfs_protocol.h" +#include "guestfs_protocol.h" #include "daemon.h" #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); @@ -170,29 +179,7 @@ do_set_e2label (const char *device, const char *label) char * do_get_e2label (const char *device) { - int r, len; - char *out, *err; - - char prog[] = "e2label"; - if (e2prog (prog) == -1) - return NULL; - - r = command (&out, &err, prog, device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - free (out); - free (err); - return NULL; - } - - free (err); - - /* Remove any trailing \n from the label. */ - len = strlen (out); - if (len > 0 && out[len-1] == '\n') - out[len-1] = '\0'; - - return out; /* caller frees */ + return do_vfs_label (device); } int @@ -219,65 +206,7 @@ do_set_e2uuid (const char *device, const char *uuid) char * do_get_e2uuid (const char *device) { - int r; - char *out, *err, *p, *q; - - /* It's not so straightforward to get the volume UUID. We have - * to use tune2fs -l and then look for a particular string in - * the output. - */ - char prog[] = "tune2fs"; - if (e2prog (prog) == -1) - return NULL; - - r = command (&out, &err, prog, "-l", device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - free (out); - free (err); - return NULL; - } - - free (err); - - /* Look for /\nFilesystem UUID:\s+/ in the output. */ - p = strstr (out, "\nFilesystem UUID:"); - if (p == NULL) { - reply_with_error ("no Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - p += 17; - while (*p && c_isspace (*p)) - p++; - if (!*p) { - reply_with_error ("malformed Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - /* Now 'p' hopefully points to the start of the UUID. */ - q = p; - while (*q && (c_isxdigit (*q) || *q == '-')) - q++; - if (!*q) { - reply_with_error ("malformed Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - *q = '\0'; - - p = strdup (p); - if (!p) { - reply_with_perror ("strdup"); - free (out); - return NULL; - } - - free (out); - return p; /* caller frees */ + return do_vfs_uuid (device); } int @@ -400,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); @@ -486,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);