Avoid zero-sized reads/writes in the FAT filesystem driver.
authorcoderain <coderain@sdf.org>
Sun, 26 Feb 2017 02:46:06 +0000 (03:46 +0100)
committercoderain <coderain@sdf.org>
Sun, 26 Feb 2017 02:46:06 +0000 (03:46 +0100)
kernel/src/drivers/fs/fat.c

index 17f5261c9b824b6193f39c679b9d3e4300e6935f..dad9ec92f19e1f6401936e59a29b2eb1409dff0d 100644 (file)
@@ -541,7 +541,7 @@ static inline dword_t fatfs_rw_file(object_t *object, byte_t *buffer, qword_t of
     dword_t cluster_size = volume->sectors_per_cluster * volume->bytes_per_sector;
     dword_t current_cluster = file->first_cluster;
 
-    while (offset_low > cluster_size)
+    while (offset_low >= cluster_size)
     {
         current_cluster = fatfs_get_next_cluster(volume, current_cluster);
         if (current_cluster >= FATFS_INVALID_CLUSTER)
@@ -557,6 +557,7 @@ static inline dword_t fatfs_rw_file(object_t *object, byte_t *buffer, qword_t of
     {
         dword_t amount = MIN(length - count, cluster_size - offset_low);
         dword_t actually_rw;
+        if (amount == 0) break;
 
         if (write)
         {