From 977b8db0d5fb74e5c5d0b1912ef68986ae201038 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Tue, 29 Apr 2025 05:11:39 +0300 Subject: Fixes --- c_implementation/src/ak_fs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/c_implementation/src/ak_fs.c b/c_implementation/src/ak_fs.c index 6a7636a..5643276 100644 --- a/c_implementation/src/ak_fs.c +++ b/c_implementation/src/ak_fs.c @@ -310,16 +310,15 @@ int ak_fs_cat_file_from_root_hash(sha512sum* rh) return 1; } is_chunk = true; - free(fullpath); } if ( !is_chunk ) { - char buffer[258]; - size_t bytes_read = fread(&buffer, sizeof(buffer), 1, fd); - fclose(fd); + char buffer[258] = {0}; + size_t bytes_read = fread(&buffer, 1, sizeof(buffer), fd); if ( bytes_read < sizeof(buffer) ) { ak_log_error(__func__, "File is smaller than expected. Wrong format?"); + fclose(fd); return 2; } if ( buffer[128] != '\n' || buffer[257] != '\n' ) @@ -349,6 +348,7 @@ int ak_fs_cat_file_from_root_hash(sha512sum* rh) if (stat(fullpath, &sb) == -1) { perror("stat"); fclose(fd); + free(fullpath); return 2; } char buffer[(long long) sb.st_size+1]; @@ -357,6 +357,7 @@ int ak_fs_cat_file_from_root_hash(sha512sum* rh) buffer[sizeof(buffer)-1] = '\0'; printf("%s", buffer); } + free(fullpath); return 0; } -- cgit v1.2.3