OSDN Git Service

Check device size on mount.
authorrelan <relan@users.noreply.github.com>
Sun, 23 Feb 2014 11:23:55 +0000 (11:23 +0000)
committerrelan <relan@users.noreply.github.com>
Mon, 24 Aug 2015 05:26:16 +0000 (08:26 +0300)
libexfat/mount.c

index c161372..70c8af5 100644 (file)
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <sys/types.h>
 
@@ -252,6 +253,18 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options)
                free(ef->sb);
                return -EIO;
        }
+       if (le64_to_cpu(ef->sb->sector_count) * SECTOR_SIZE(*ef->sb) >
+                       exfat_get_size(ef->dev))
+       {
+               free(ef->zero_cluster);
+               exfat_error("file system is larger than underlying device: "
+                               "%"PRIu64" > %"PRIu64,
+                               le64_to_cpu(ef->sb->sector_count) * SECTOR_SIZE(*ef->sb),
+                               exfat_get_size(ef->dev));
+               exfat_close(ef->dev);
+               free(ef->sb);
+               return -EIO;
+       }
 
        ef->root = malloc(sizeof(struct exfat_node));
        if (ef->root == NULL)