From 4ba7fc3b7cf05761f2b2a2f86cbb13ee6502f27b Mon Sep 17 00:00:00 2001 From: janwas Date: Wed, 2 Jun 2004 16:12:13 +0000 Subject: [PATCH] yet more tree_lookup fixes for bug pointed out by simon This was SVN commit r358. --- source/lib/res/vfs.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/source/lib/res/vfs.cpp b/source/lib/res/vfs.cpp index d326aa001c..422ec09503 100755 --- a/source/lib/res/vfs.cpp +++ b/source/lib/res/vfs.cpp @@ -350,7 +350,6 @@ static int tree_lookup(const char* path, const FileLoc** const loc = 0, Dir** co Dir* cur_dir = &vfs_root; const char* cur_component = buf; - bool is_last_component = false; // subdirectory traverse logic // valid: @@ -373,29 +372,26 @@ static int tree_lookup(const char* path, const FileLoc** const loc = 0, Dir** co char* slash = strchr(cur_component, '/'); if(slash) *slash = 0; - // allow root dir ("") and trailing '/' if looking up a dir + + // early outs: + // .. last component and it's a filename + if(slash == 0 && loc != 0) + break; + // .. root dir ("") or trailing '/' in dir name if(*cur_component == '\0' && loc == 0) break; - is_last_component = (slash == 0); // create subdir (no-op if it already exists) if(create_missing_components) cur_dir->add_subdir(cur_component); // switch to - Dir* subdir = cur_dir->find_subdir(cur_component); - if(!subdir) - { - // this last component is a filename. - if(is_last_component && loc != 0) - break; - // otherwise, we had an (invalid) subdir name - fail. + cur_dir = cur_dir->find_subdir(cur_component); + if(!cur_dir) return -ENOENT; - } - cur_dir = subdir; // don't assign if invalid - need cur_dir below. // next component - if(is_last_component) + if(!slash) // done, no more components left break; cur_component = slash+1; }