Fixed implementation of ChRoot
authorJohn Hodge <[email protected]>
Mon, 16 Nov 2009 03:14:17 +0000 (11:14 +0800)
committerJohn Hodge <[email protected]>
Mon, 16 Nov 2009 03:14:17 +0000 (11:14 +0800)
(it could be bypassed by using ..)

Kernel/vfs/open.c

index 7382a0c..507f182 100644 (file)
@@ -39,7 +39,6 @@ char *VFS_GetAbsPath(char *Path)
        char    *cwd = CFGPTR(CFG_VFS_CWD);
         int    cwdLen;
        
        char    *cwd = CFGPTR(CFG_VFS_CWD);
         int    cwdLen;
        
-       
        ENTER("sPath", Path);
        
        // Memory File
        ENTER("sPath", Path);
        
        // Memory File
@@ -54,6 +53,7 @@ char *VFS_GetAbsPath(char *Path)
                return ret;
        }
        
                return ret;
        }
        
+       // - Fetch ChRoot
        if( chroot == NULL ) {
                chroot = "";
                chrootLen = 0;
        if( chroot == NULL ) {
                chroot = "";
                chrootLen = 0;
@@ -63,13 +63,12 @@ char *VFS_GetAbsPath(char *Path)
        
        // Check if the path is already absolute
        if(Path[0] == '/') {
        
        // Check if the path is already absolute
        if(Path[0] == '/') {
-               ret = malloc(chrootLen + pathLen + 1);
+               ret = malloc(pathLen + 1);
                if(!ret) {
                        Warning("VFS_GetAbsPath - malloc() returned NULL");
                        return NULL;
                }
                if(!ret) {
                        Warning("VFS_GetAbsPath - malloc() returned NULL");
                        return NULL;
                }
-               strcpy(ret, chroot);
-               strcpy(ret+chrootLen, Path);
+               strcpy(ret, Path);
        } else {
                if(cwd == NULL) {
                        cwd = "/";
        } else {
                if(cwd == NULL) {
                        cwd = "/";
@@ -153,6 +152,14 @@ char *VFS_GetAbsPath(char *Path)
        else
                ret[iPos2] = 0;
        
        else
                ret[iPos2] = 0;
        
+       
+       // Prepend the chroot
+       tmpStr = malloc(chrootLen + strlen(ret) + 1);
+       strcpy( tmpStr, chroot );
+       strcpy( tmpStr+chrootLen, ret );
+       free(ret);
+       ret = tmpStr;
+       
        LEAVE('s', ret);
        //Log("VFS_GetAbsPath: RETURN '%s'", ret);
        return ret;
        LEAVE('s', ret);
        //Log("VFS_GetAbsPath: RETURN '%s'", ret);
        return ret;

UCC git Repository :: git.ucc.asn.au