From 21a30db5d303c0c95cd3866b4bfd1b394b49f658 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Sun, 1 Oct 2023 20:47:09 -0400 Subject: [PATCH] Prevent ls from running on files --- bin/ls/ls.c | 4 ++-- sys/fs/o2fs/o2fs.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 9ae4682..3ca56d7 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -35,8 +35,8 @@ main(int argc, const char *argv[]) break; } if (status < 0) { - fputs("Error\n", stdout); - break; + printf("OSReadDir Error: %x\n", -status); + return 1; } printf("%s\n", de.d_name); diff --git a/sys/fs/o2fs/o2fs.c b/sys/fs/o2fs/o2fs.c index d3074e7..209af02 100644 --- a/sys/fs/o2fs/o2fs.c +++ b/sys/fs/o2fs/o2fs.c @@ -364,8 +364,11 @@ O2FS_ReadDir(VNode *fn, void *buf, uint64_t len, uint64_t *off) status = O2FS_Read(fn, &dirEntry, *off, sizeof(dirEntry)); if (status != sizeof(dirEntry)) { - kprintf("Unexpected error reading directory: %d", status); - return status; + kprintf("Unexpected error reading directory: %d\n", status); + return -ENOTDIR; + } + if (strncmp((char *)&dirEntry.magic[0], BDIR_MAGIC, sizeof(dirEntry.magic)) != 0) { + return -ENOTDIR; } // XXX: Validation and fill in all fields