r3198: check for too many .. components in filenames
authorAndrew Tridgell <tridge@samba.org>
Mon, 25 Oct 2004 06:23:28 +0000 (06:23 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:04:40 +0000 (13:04 -0500)
pvfs now passes RAW-MKDIR

source/ntvfs/posix/pvfs_resolve.c
source/script/tests/test_posix.sh
source/torture/raw/mkdir.c

index 5b86cd3a7311602ac1c385b3887e7caf60520943..5d9827451189e7fc36feecd388cba607899de619 100644 (file)
@@ -180,8 +180,9 @@ static NTSTATUS pvfs_case_search(struct pvfs_state *pvfs, struct pvfs_filename *
 static NTSTATUS pvfs_unix_path(struct pvfs_state *pvfs, const char *cifs_name,
                               uint_t flags, struct pvfs_filename *name)
 {
-       char *ret, *p;
+       char *ret, *p, *p_start;
        size_t len;
+       int num_components=0;
 
        name->original_name = talloc_strdup(name, cifs_name);
        name->stream_name = NULL;
@@ -217,6 +218,7 @@ static NTSTATUS pvfs_unix_path(struct pvfs_state *pvfs, const char *cifs_name,
 
        /* now do an in-place conversion of '\' to '/', checking
           for legal characters */
+       p_start = p;
        while (*p) {
                size_t c_size;
                codepoint_t c = next_codepoint(p, &c_size);
@@ -228,6 +230,7 @@ static NTSTATUS pvfs_unix_path(struct pvfs_state *pvfs, const char *cifs_name,
                                return NT_STATUS_ILLEGAL_CHARACTER;
                        }
                        *p = '/';
+                       num_components++;
                        break;
                case ':':
                        if (!(flags & PVFS_RESOLVE_STREAMS)) {
@@ -252,6 +255,18 @@ static NTSTATUS pvfs_unix_path(struct pvfs_state *pvfs, const char *cifs_name,
                case '/':
                case '|':
                        return NT_STATUS_ILLEGAL_CHARACTER;
+               case '.':
+                       if (p[1] != '.' ||
+                           (p[2] != '\\' && p[2] != 0) ||
+                           (p != p_start && p[-1] != '/')) {
+                               break;
+                       }
+                       /* its definately a .. component */
+                       num_components--;
+                       if (num_components <= 0) {
+                               return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
+                       }
+                       break;
                }
 
                p += c_size;
index 414cf30a676a7a2c4c3ee4d226fc62232e5193d3..0db84a83ed82fb63a418b2cac3c6200c880ca3bb 100755 (executable)
@@ -30,7 +30,7 @@ testit() {
 
 tests="BASE-FDPASS BASE-LOCK1 BASE-LOCK2 BASE-LOCK3 BASE-LOCK4"
 tests="$tests BASE-LOCK5 BASE-LOCK6 BASE-LOCK7 BASE-UNLINK BASE-ATTR"
-tests="$tests BASE-NEGNOWAIT BASE-DIR"
+tests="$tests BASE-NEGNOWAIT BASE-DIR RAW-MKDIR"
 tests="$tests BASE-DENY2 BASE-TCON BASE-TCONDEV BASE-RW1"
 tests="$tests BASE-DENY3 BASE-XCOPY"
 tests="$tests BASE-DELETE BASE-PROPERTIES BASE-MANGLE"
@@ -40,7 +40,7 @@ tests="$tests RAW-LOCK RAW-SEEK RAW-CONTEXT BASE-RENAME"
 
 
 soon="BASE-DIR1 BASE-DENY1 BASE-VUID BASE-OPEN BASE-DEFER_OPEN BASE-OPENATTR BASE-CHARSET"
-soon="$soon RAW-SFILEINFO RAW-SEARCH RAW-OPEN RAW-MKDIR RAW-OPLOCK RAW-NOTIFY RAW-MUX RAW-IOCTL"
+soon="$soon RAW-SFILEINFO RAW-SEARCH RAW-OPEN RAW-OPLOCK RAW-NOTIFY RAW-MUX RAW-IOCTL"
 soon="$soon RAW-CHKPATH RAW-UNLINK RAW-READ RAW-WRITE RAW-RENAME RAW-CLOSE BASE-TRANS2"
 
 for t in $tests; do
index bc2ddbb5446a107947e71c1a1d644fd20f3f21d0..48c485355434c6cc65f1c366ebebb7b4ad7ac2da 100644 (file)
@@ -22,8 +22,8 @@
 
 #define CHECK_STATUS(status, correct) do { \
        if (!NT_STATUS_EQUAL(status, correct)) { \
-               printf("(%d) Incorrect status %s - should be %s\n", \
-                      __LINE__, nt_errstr(status), nt_errstr(correct)); \
+               printf("(%s) Incorrect status %s - should be %s\n", \
+                      __location__, nt_errstr(status), nt_errstr(correct)); \
                ret = False; \
                goto done; \
        }} while (0)