]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fs/squashfs: sqfs_read: don't write beyond buffer size
authorRichard Genoud <richard.genoud@posteo.net>
Tue, 3 Nov 2020 11:11:23 +0000 (12:11 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 19 Nov 2020 14:45:49 +0000 (09:45 -0500)
The length of the buffer wasn't taken into account when writing to the
given buffer.

Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
fs/squashfs/sqfs.c

index 435081638b8c00528f4e87f8c5dbd45d8f838ad3..1ecdd01cf7cabfddb16303242c40c1bfaff9995f 100644 (file)
@@ -1415,6 +1415,8 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
                }
 
                finfo.size = len;
+       } else {
+               len = finfo.size;
        }
 
        if (datablk_count) {
@@ -1461,9 +1463,13 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
                        if (ret)
                                goto out;
 
+                       if ((*actread + dest_len) > len)
+                               dest_len = len - *actread;
                        memcpy(buf + offset + *actread, datablock, dest_len);
                        *actread += dest_len;
                } else {
+                       if ((*actread + table_size) > len)
+                               table_size = len - *actread;
                        memcpy(buf + offset + *actread, data, table_size);
                        *actread += table_size;
                }
@@ -1471,6 +1477,8 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
                data_offset += table_size;
                free(data_buffer);
                data_buffer = NULL;
+               if (*actread >= len)
+                       break;
        }
 
        /*