Whamcloud - gitweb
LU-3014 utils: Fix an offset overflow in file_create()
[fs/lustre-release.git] / lustre / utils / mount_utils.c
index 00e5d5c..00400df 100644 (file)
@@ -689,11 +689,23 @@ __u64 get_device_size(char* device)
        return size >> 10;
 }
 
-int file_create(char *path, int size)
+int file_create(char *path, __u64 size)
 {
+       __u64 size_max;
        int ret;
        int fd;
 
+       /*
+        * Since "size" is in KB, the file offset it represents could overflow
+        * off_t.
+        */
+       size_max = (off_t)1 << (_FILE_OFFSET_BITS - 1 - 10);
+       if (size >= size_max) {
+               fprintf(stderr, "%s: %llu KB: Backing store size must be "
+                       "smaller than %llu KB\n", progname, size, size_max);
+               return EFBIG;
+       }
+
        ret = access(path, F_OK);
        if (ret == 0) {
                ret = unlink(path);