]> git.wh0rd.org - dump.git/blobdiff - compat/lib/bylabel.c
Be sure the di_size in a map header has the correct value.
[dump.git] / compat / lib / bylabel.c
index 07f0dd92320ccb112b773a9eb54e44b1a826256c..5a40a70e6eb5af34dfbe3d388a99904a38c80df2 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <config.h>
 #include <compatlfs.h>
+#include <sys/types.h>
 #include <stdio.h>
 #include <sys/param.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <malloc.h>
+#include <sys/cdefs.h>
 #include "bylabel.h"
 
+#ifndef HAVE_BLKID
+
 #define PROC_PARTITIONS "/proc/partitions"
 #define DEVLABELDIR    "/dev"
 
 #define EXT2_SUPER_SIZE                sizeof(struct ext2_super_block)
 #define EXT2_SUPER_MAGIC       0xEF53
 
+#define VOLNAMSZ       16
+
 struct ext2_super_block {
        unsigned char   s_dummy1[56];
        unsigned char   s_magic[2];
        unsigned char   s_dummy2[46];
        unsigned char   s_uuid[16];
-       unsigned char   s_volume_name[16];
+       unsigned char   s_volume_name[VOLNAMSZ];
 };
 #define ext2magic(s)   ((unsigned int) s.s_magic[0] + (((unsigned int) s.s_magic[1]) << 8))
 
@@ -71,7 +77,9 @@ get_label_uuid(const char *device, char **label, char *uuid) {
 
        /* superblock is ext2 - now what is its label? */
        memcpy(uuid, e2sb.s_uuid, sizeof(e2sb.s_uuid));
-       *label = strdup(e2sb.s_volume_name);
+       *label = malloc(VOLNAMSZ + 1);
+       strncpy(*label, e2sb.s_volume_name, VOLNAMSZ);
+       (*label)[VOLNAMSZ] = 0;
 
        return 0;
 }
@@ -249,3 +257,5 @@ get_device_label(const char * spec) {
        }
        return NULL;
 }
+
+#endif /* !HAVE_BLKID */