Tcl Source Code

Check-in [b5dd510e85]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix [3118489]: NUL in filenames, now fixed for both Windows and UNIX. For consistancy, any NUL character in a filename prevents the native filesystem to generate a native file representation for it. Other filesystems than the native one may still accept it, but it's not recommended.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b5dd510e85bb0711c9f00a94620d602ffd2a9350
User & Date: jan.nijtmans 2014-04-11 09:55:15
References
2014-04-11
09:52 Ticket [3118489fff] NUL in filenames status still Open with 3 other changes artifact: 225f0ad2b1 user: jan.nijtmans
Context
2014-04-14
18:45
[e663138a06] Fix the new INST_NUM_TYPE instruction so that the boundary cases of [string is] on inte... check-in: 5eae727664 user: dgp tags: trunk
2014-04-11
09:55
Fix [3118489]: NUL in filenames, now fixed for both Windows and UNIX. For consistancy, any NUL char... check-in: b5dd510e85 user: jan.nijtmans tags: trunk
08:23
Fix [3118489] for Windows only: NUL in filenames. This allows various characters to be used in win32... check-in: 0f4597a73c user: jan.nijtmans tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to tests/cmdAH.test.

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    set dir [pwd]
} -body {
    cd /
    pwd
} -cleanup {
    cd $dir
} -result {/}
test cmdAH-2.6.3 {Tcl_CdObjCmd, bug #3118489} -constraints win -returnCodes error -body {
    cd .\0
} -result "couldn't change working directory to \".\0\": no such file or directory"
test cmdAH-2.7 {Tcl_ConcatObjCmd} {
    concat
} {}
test cmdAH-2.8 {Tcl_ConcatObjCmd} {
    concat a







|







137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    set dir [pwd]
} -body {
    cd /
    pwd
} -cleanup {
    cd $dir
} -result {/}
test cmdAH-2.6.3 {Tcl_CdObjCmd, bug #3118489} -returnCodes error -body {
    cd .\0
} -result "couldn't change working directory to \".\0\": no such file or directory"
test cmdAH-2.7 {Tcl_ConcatObjCmd} {
    concat
} {}
test cmdAH-2.8 {Tcl_ConcatObjCmd} {
    concat a

Changes to unix/tclUnixFile.c.

1101
1102
1103
1104
1105
1106
1107






1108
1109
1110
1111
1112
1113
1114
	}
	Tcl_IncrRefCount(validPathPtr);
    }

    str = Tcl_GetStringFromObj(validPathPtr, &len);
    Tcl_UtfToExternalDString(NULL, str, len, &ds);
    len = Tcl_DStringLength(&ds) + sizeof(char);






    Tcl_DecrRefCount(validPathPtr);
    nativePathPtr = ckalloc(len);
    memcpy(nativePathPtr, Tcl_DStringValue(&ds), (size_t) len);

    Tcl_DStringFree(&ds);
    return nativePathPtr;
}







>
>
>
>
>
>







1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
	}
	Tcl_IncrRefCount(validPathPtr);
    }

    str = Tcl_GetStringFromObj(validPathPtr, &len);
    Tcl_UtfToExternalDString(NULL, str, len, &ds);
    len = Tcl_DStringLength(&ds) + sizeof(char);
    if (strlen(Tcl_DStringValue(&ds)) < len - sizeof(char)) {
	/* See bug [3118489]: NUL in filenames */
	Tcl_DecrRefCount(validPathPtr);
	Tcl_DStringFree(&ds);
	return NULL;
    }
    Tcl_DecrRefCount(validPathPtr);
    nativePathPtr = ckalloc(len);
    memcpy(nativePathPtr, Tcl_DStringValue(&ds), (size_t) len);

    Tcl_DStringFree(&ds);
    return nativePathPtr;
}

Changes to win/tclWinFile.c.

1812
1813
1814
1815
1816
1817
1818



1819
1820
1821
1822
1823
1824
1825
    Tcl_Obj *pathPtr)	/* Path to new working directory. */
{
    int result;
    const TCHAR *nativePath;

    nativePath = Tcl_FSGetNativePath(pathPtr);




    result = SetCurrentDirectory(nativePath);

    if (result == 0) {
	TclWinConvertError(GetLastError());
	return -1;
    }
    return 0;







>
>
>







1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
    Tcl_Obj *pathPtr)	/* Path to new working directory. */
{
    int result;
    const TCHAR *nativePath;

    nativePath = Tcl_FSGetNativePath(pathPtr);

    if (!nativePath) {
	return -1;
    }
    result = SetCurrentDirectory(nativePath);

    if (result == 0) {
	TclWinConvertError(GetLastError());
	return -1;
    }
    return 0;
2925
2926
2927
2928
2929
2930
2931






2932
2933
2934
2935
2936
2937
2938

    str = Tcl_GetStringFromObj(validPathPtr, &len);
    Tcl_WinUtfToTChar(str, len, &ds);
    len = Tcl_DStringLength(&ds) + sizeof(WCHAR);
    wp = (WCHAR *) Tcl_DStringValue(&ds);
    for (i=sizeof(WCHAR); i<len; ++wp,i+=sizeof(WCHAR)) {
	if ( (*wp < ' ') || wcschr(L"\"*<>|", *wp) ){






	    *wp |= 0xF000;
	}else if (*wp=='/') {
	    *wp = '\\';
	}
    }
    Tcl_DecrRefCount(validPathPtr);
    nativePathPtr = ckalloc(len);







>
>
>
>
>
>







2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947

    str = Tcl_GetStringFromObj(validPathPtr, &len);
    Tcl_WinUtfToTChar(str, len, &ds);
    len = Tcl_DStringLength(&ds) + sizeof(WCHAR);
    wp = (WCHAR *) Tcl_DStringValue(&ds);
    for (i=sizeof(WCHAR); i<len; ++wp,i+=sizeof(WCHAR)) {
	if ( (*wp < ' ') || wcschr(L"\"*<>|", *wp) ){
	    if (!*wp){
		/* See bug [3118489]: NUL in filenames */
		Tcl_DecrRefCount(validPathPtr);
		Tcl_DStringFree(&ds);
		return NULL;
	    }
	    *wp |= 0xF000;
	}else if (*wp=='/') {
	    *wp = '\\';
	}
    }
    Tcl_DecrRefCount(validPathPtr);
    nativePathPtr = ckalloc(len);