btrfs: print an error if finding compressed/encrypted data
authorH. Peter Anvin <hpa@zytor.com>
Tue, 6 Jul 2010 00:50:13 +0000 (17:50 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 6 Jul 2010 00:50:13 +0000 (17:50 -0700)
If we find compressed or encrypted data, print an error message
instead of returning garbage.  This is suboptimal, but at least
handles the common subcase of an encrypted configuration file.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/fs/btrfs/btrfs.c
core/fs/getfssec.c

index 55dce93..b6a14e3 100644 (file)
@@ -530,10 +530,19 @@ static int btrfs_next_extent(struct inode *inode, uint32_t lstart)
        ret = search_tree(fs, fs_tree, &search_key, &path);
        if (ret) { /* impossible */
                printf("btrfs: search extent data error!\n");
-               return 0;
+               return -1;
        }
        extent_item = *(struct btrfs_file_extent_item *)path.data;
 
+       if (extent_item.encryption) {
+           printf("btrfs: found encrypted data, cannot continue!\n");
+           return -1;
+       }
+       if (extent_item.compression) {
+           printf("btrfs: found compressed data, cannot continue!\n");
+           return -1;
+       }
+
        if (extent_item.type == BTRFS_FILE_EXTENT_INLINE) {/* inline file */
                /* we fake a extent here, and PVT of inode will tell us */
                offset = path.offsets[0] + sizeof(struct btrfs_header)
index 3d62d4e..e099b64 100644 (file)
@@ -144,6 +144,10 @@ uint32_t generic_getfssec(struct file *file, char *buf,
            if (!inode->this_extent.len) {
                /* Doesn't matter if it's contiguous... */
                inode->this_extent = inode->next_extent;
+               if (!inode->next_extent.len) {
+                   sectors = 0; /* Failed to get anything... we're dead */
+                   break;
+               }
            } else if (inode->next_extent.len &&
                inode->next_extent.pstart == next_pstart(&inode->this_extent)) {
                /* Coalesce extents and loop */