From: John Hodge Date: Tue, 14 Feb 2012 07:34:05 +0000 (+0800) Subject: Kernel/vfs - Fixed edge case bug with chroots X-Git-Tag: rel0.15~774 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=7dcbae6762b50bdd450559ca455f2374a09f1df9;p=tpg%2Facess2.git Kernel/vfs - Fixed edge case bug with chroots - Trims trailing slash off chroot --- diff --git a/KernelLand/Kernel/vfs/fs/devfs.c b/KernelLand/Kernel/vfs/fs/devfs.c index b3f4a579..13552260 100644 --- a/KernelLand/Kernel/vfs/fs/devfs.c +++ b/KernelLand/Kernel/vfs/fs/devfs.c @@ -3,6 +3,7 @@ * Device Filesystem (DevFS) * - vfs/fs/devfs.c */ +#define DEBUG 0 #include #include #include @@ -44,6 +45,9 @@ int DevFS_AddDevice(tDevFS_Driver *Device) { int ret = 0; tDevFS_Driver *dev; + + ENTER("pDevice", Device); + LOG("Device->Name = '%s'", Device->Name); SHORTLOCK( &glDevFS_ListLock ); @@ -61,7 +65,7 @@ int DevFS_AddDevice(tDevFS_Driver *Device) else Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p", Device, dev->Name, dev); - ret = 0; // Error + ret = -1; // Error } else { Device->Next = gDevFS_Drivers; @@ -71,6 +75,7 @@ int DevFS_AddDevice(tDevFS_Driver *Device) } SHORTREL( &glDevFS_ListLock ); + LEAVE('i', ret); return ret; } @@ -140,7 +145,7 @@ tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name) { tDevFS_Driver *dev; - //ENTER("pNode sName", Node, Name); + ENTER("pNode sName", Node, Name); for(dev = gDevFS_Drivers; dev; @@ -148,14 +153,14 @@ tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name) ) { //LOG("dev = %p", dev); - //LOG("dev->Name = '%s'", dev->Name); + LOG("dev->Name = '%s'", dev->Name); if(strcmp(dev->Name, Name) == 0) { - //LEAVE('p', &dev->RootNode); + LEAVE('p', &dev->RootNode); return &dev->RootNode; } } - //LEAVE('n'); + LEAVE('n'); return NULL; } diff --git a/KernelLand/Kernel/vfs/fs/root.c b/KernelLand/Kernel/vfs/fs/root.c index 9fa1732b..bee20305 100644 --- a/KernelLand/Kernel/vfs/fs/root.c +++ b/KernelLand/Kernel/vfs/fs/root.c @@ -142,14 +142,20 @@ tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name) tRamFS_File *parent = Node->ImplPtr; tRamFS_File *child = parent->Data.FirstChild; + ENTER("pNode sName", Node, Name); //Log("Root_FindDir: (Node=%p, Name='%s')", Node, Name); for(;child;child = child->Next) { //Log(" Root_FindDir: strcmp('%s', '%s')", child->Node.Name, Name); - if(strcmp(child->Name, Name) == 0) return &child->Node; + LOG("child->Name = '%s'", child->Name); + if(strcmp(child->Name, Name) == 0) { + LEAVE('p', &child->Node); + return &child->Node; + } } + LEAVE('n'); return NULL; } diff --git a/KernelLand/Kernel/vfs/open.c b/KernelLand/Kernel/vfs/open.c index 1536d1a0..cfb296b6 100644 --- a/KernelLand/Kernel/vfs/open.c +++ b/KernelLand/Kernel/vfs/open.c @@ -59,6 +59,9 @@ char *VFS_GetAbsPath(const char *Path) if( chroot == NULL ) chroot = ""; chrootLen = strlen(chroot); + // Trim trailing slash off chroot + if( chrootLen && chroot[chrootLen - 1] == '/' ) + chrootLen -= 1; // Check if the path is already absolute if(Path[0] == '/') { @@ -269,14 +272,14 @@ restart_parse: // Check permissions on root of filesystem if( !VFS_CheckACL(curNode, VFS_PERM_EXECUTE) ) { - //Log("Permissions fail on '%s'", Path); + LOG("Permissions failure on '%s'", Path); goto _error; } // Check if the node has a FindDir method if( !curNode->Type->FindDir ) { - //Log("FindDir fail on '%s'", Path); + LOG("Finddir failure on '%s'", Path); goto _error; } LOG("FindDir{=%p}(%p, '%s')", curNode->Type->FindDir, curNode, pathEle);