From d3d587771337d495b34f5a7967496cd2181eff15 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 26 Dec 2015 21:47:32 +0000 Subject: [PATCH] filesys: Fix trailing / handling (hopefully) Also fix a bug in null name handling --- Kernel/filesys.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Kernel/filesys.c b/Kernel/filesys.c index 56fbc07f..feddbdcd 100644 --- a/Kernel/filesys.c +++ b/Kernel/filesys.c @@ -355,10 +355,17 @@ void filename(char *userspace_upath, char *name) return; /* An access violation reading the name */ } ptr = buf; + /* Find the end of the buffer */ while(*ptr) ++ptr; - /* Special case for "...name.../" */ - while(*ptr != '/' && ptr-- > buf); + /* Special case for "...name.../". SuS requires that mkdir foo/ works + (see the clarifications to the standard) */ + if (*--ptr == '/') + *ptr-- = 0; + /* Walk back until we drop off the start of the buffer or find the + slash */ + while(*ptr != '/' && ptr-- >= buf); + /* And move past the slash, or not the string start */ ptr++; memcpy(name, ptr, FILENAME_LEN); brelse(buf); @@ -480,7 +487,6 @@ uint16_t i_alloc(uint16_t devno) { staticfast fsptr dev; staticfast blkno_t blk; - staticfast struct mount *m; struct dinode *buf; staticfast uint16_t j; uint16_t k; @@ -488,7 +494,6 @@ uint16_t i_alloc(uint16_t devno) if(baddev(dev = getdev(devno))) goto corrupt; - m = fs_tab_get(devno); tryagain: if(dev->s_ninode) { -- 2.34.1