From 9367202dbcaa3ea406a1f1bc134f196a8d466fd3 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Nov 2025 21:28:27 +0000 Subject: [PATCH 1/2] Fix assertion failures in tinydfs_test Fixed two critical bugs in the TinyDFS client code: 1. Added bounds checking in alloc_operation() to prevent buffer overflow when searching for a free operation slot. The while loop could go past the end of the operations array, causing undefined behavior. 2. Fixed all tinydfs_submit_* functions to return the operation index (opidx) instead of 0 on success. This was causing all operations to be tracked with index 0, leading to type mismatches between operation types and result types, which triggered the assertion: "Assertion `pending.type == PENDING_OPERATION_DELETE' failed" The test now runs successfully past the original assertion point. --- src/client.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/client.c b/src/client.c index 107445f..f06474d 100644 --- a/src/client.c +++ b/src/client.c @@ -219,8 +219,10 @@ alloc_operation(TinyDFS *tdfs, OperationType type, int off, void *ptr, int len) if (tdfs->num_operations == MAX_OPERATIONS) return -1; Operation *o = tdfs->operations; - while (o->type != OPERATION_TYPE_FREE) + while (o - tdfs->operations < MAX_OPERATIONS && o->type != OPERATION_TYPE_FREE) o++; + if (o - tdfs->operations >= MAX_OPERATIONS) + return -1; o->type = type; o->ptr = ptr; o->off = off; @@ -418,7 +420,7 @@ int tinydfs_submit_create(TinyDFS *tdfs, char *path, int path_len, return -1; } - return 0; + return opidx; } int tinydfs_submit_delete(TinyDFS *tdfs, char *path, int path_len) @@ -444,7 +446,7 @@ int tinydfs_submit_delete(TinyDFS *tdfs, char *path, int path_len) return -1; } - return 0; + return opidx; } int tinydfs_submit_list(TinyDFS *tdfs, char *path, int path_len) @@ -471,7 +473,7 @@ int tinydfs_submit_list(TinyDFS *tdfs, char *path, int path_len) return -1; } - return 0; + return opidx; } static int send_read_message(TinyDFS *tdfs, int opidx, int tag, string path, uint32_t offset, uint32_t length) @@ -504,7 +506,7 @@ int tinydfs_submit_read(TinyDFS *tdfs, char *path, int path_len, int off, void * return -1; } - return 0; + return opidx; } int tinydfs_submit_write(TinyDFS *tdfs, char *path, int path_len, int off, void *src, int len) @@ -522,7 +524,7 @@ int tinydfs_submit_write(TinyDFS *tdfs, char *path, int path_len, int off, void return -1; } - return 0; + return opidx; } void tinydfs_result_free(TinyDFS_Result *result) From 537fbc655fb244ded8426d48bf88620fbc4fea6b Mon Sep 17 00:00:00 2001 From: Francesco Cozzuto Date: Sat, 8 Nov 2025 22:35:20 +0100 Subject: [PATCH 2/2] Progress --- Makefile | 2 +- src/simulation_client.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0ffbde1..d282153 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CFLAGS = -Wall -Wextra -ggdb -fsanitize=address,undefined +CFLAGS = -Wall -Wextra -ggdb ifeq ($(OS),Windows_NT) LFLAGS = -lws2_32 diff --git a/src/simulation_client.h b/src/simulation_client.h index abf1caf..6d4bb05 100644 --- a/src/simulation_client.h +++ b/src/simulation_client.h @@ -12,7 +12,7 @@ #include "TinyDFS.h" -#define MAX_PENDING_OPERATION 128 +#define MAX_PENDING_OPERATION 8 typedef enum { PENDING_OPERATION_CREATE,