From 5843870c1d9696f6db072b8b3b5fb51cea19a678 Mon Sep 17 00:00:00 2001 From: Sparchatus Date: Tue, 31 May 2022 09:59:12 +0000 Subject: [PATCH] Disallow writes to readonly file --- lib/fs/fat32.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/fs/fat32.c b/lib/fs/fat32.c index 9fe9693..f906436 100644 --- a/lib/fs/fat32.c +++ b/lib/fs/fat32.c @@ -1526,6 +1526,11 @@ static errval_t _fat32_fwrite(struct fat32 *fat32, struct fat32_handle *file_han err = fat32_read_directory_entry(fat32, file_handle->directory_entry_ref, &directory_entry); if (err_is_fail(err)) return err; + // check if the directory entry is readonly + if (directory_entry.attributes & FAT32_ATTR_READ_ONLY) { + return FS_ERR_WRITE; + } + // if the current position in the file is past the end we need to increase the file size accordingly if (file_handle->byte_offset >= directory_entry.file_size || file_handle->current_cluster == 0) { // debug_printf("Invalid current cluster %u, updating it: %u (%lu)\n", file_handle->current_cluster, file_handle->first_cluster, file_handle->byte_offset);