diff --git a/tasks/fs0/main.c b/tasks/fs0/main.c index c34709d..2c720a7 100644 --- a/tasks/fs0/main.c +++ b/tasks/fs0/main.c @@ -93,7 +93,7 @@ void handle_fs_requests(void) (unsigned long)mr[2], (void *)mr[3]); break; default: - printf("%s: Unrecognised ipc tag (%d)" + printf("%s: Unrecognised ipc tag (%d) " "received. Ignoring.\n", __TASKNAME__, mr[MR_TAG]); } } diff --git a/tasks/fs0/src/syscalls.c b/tasks/fs0/src/syscalls.c index c829720..22e0712 100644 --- a/tasks/fs0/src/syscalls.c +++ b/tasks/fs0/src/syscalls.c @@ -129,6 +129,7 @@ int sys_open(l4id_t sender, const char *pathname, int flags, unsigned int mode) /* Get a new fd */ BUG_ON((fd = id_new(task->fdpool)) < 0); + retval = fd; /* Assign the new fd with the vnode's number */ task->fd[fd] = v->vnum; @@ -339,6 +340,11 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count) return 0; } + if (fd < 0 || fd > TASK_OFILES_MAX) { + l4_ipc_return(-EBADF); + return 0; + } + /* Convert fd to vnum. */ BUG_ON((vnum = t->fd[fd]) < 0); diff --git a/tasks/test0/src/dirtest.c b/tasks/test0/src/dirtest.c index 92f74d4..8c7e71c 100644 --- a/tasks/test0/src/dirtest.c +++ b/tasks/test0/src/dirtest.c @@ -111,14 +111,14 @@ int lsdir(char *path) memset(dents, 0, sizeof(struct dirent) * DENTS_TOTAL); if ((fd = open(path, O_RDONLY)) < 0) { - printf("OPEN failed."); - return 0; + printf("OPEN failed.\n"); + return -1; } else printf("Got fd: %d for opening %s\n", fd, path); if ((bytes = os_readdir(fd, dents, sizeof(struct dirent) * DENTS_TOTAL)) < 0) { - perror("GETDENTS\n"); - return 0; + printf("GETDENTS error: %d\n", bytes); + return -1; } else { print_dirents(path, dents, bytes); } @@ -130,9 +130,15 @@ int lsdir(char *path) int dirtest(void) { printf("\nlsdir current directory:\n"); - lsdir("."); + if (lsdir(".") < 0) { + printf("lsdir failed.\n"); + goto out_err; + } printf("\nlsdir root directory:\n"); - lsdir("/"); + if (lsdir("/") < 0) { + printf("lsdir failed.\n"); + goto out_err; + } printf("\nCreating directories: usr, etc, tmp, var, home, opt, bin, boot, lib, dev\n"); if (mkdir("/usr", 0) < 0) @@ -173,5 +179,8 @@ int dirtest(void) printf("\nlsdir /usr/./././bin//\n"); lsdir("/usr/./././bin//"); return 0; + +out_err: + return 0; }