summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <jan.nijtmans@noemail.net>2014-04-11 09:55:15 (GMT)
committerjan.nijtmans <jan.nijtmans@noemail.net>2014-04-11 09:55:15 (GMT)
commit98187f008f8651c3862c163671694705b4611655 (patch)
tree0f4d9ae96ae10ac94173c5e8e4dff3e78801b2ec
parent60aceb7be9af6a879562bec7c00f0938e59a6705 (diff)
downloadtcl-98187f008f8651c3862c163671694705b4611655.zip
tcl-98187f008f8651c3862c163671694705b4611655.tar.gz
tcl-98187f008f8651c3862c163671694705b4611655.tar.bz2
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. FossilOrigin-Name: b5dd510e85bb0711c9f00a94620d602ffd2a9350
-rw-r--r--tests/cmdAH.test2
-rw-r--r--unix/tclUnixFile.c6
-rw-r--r--win/tclWinFile.c9
3 files changed, 16 insertions, 1 deletions
diff --git a/tests/cmdAH.test b/tests/cmdAH.test
index 80706b6..04a86fa 100644
--- a/tests/cmdAH.test
+++ b/tests/cmdAH.test
@@ -141,7 +141,7 @@ test cmdAH-2.6.2 {cd} -constraints {unix nonPortable} -setup {
} -cleanup {
cd $dir
} -result {/}
-test cmdAH-2.6.3 {Tcl_CdObjCmd, bug #3118489} -constraints win -returnCodes error -body {
+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} {
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c
index 5bfe5d9..2cb0027 100644
--- a/unix/tclUnixFile.c
+++ b/unix/tclUnixFile.c
@@ -1105,6 +1105,12 @@ TclNativeCreateNativeRep(
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);
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index c9b95a0..fc0ac9e 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -1816,6 +1816,9 @@ TclpObjChdir(
nativePath = Tcl_FSGetNativePath(pathPtr);
+ if (!nativePath) {
+ return -1;
+ }
result = SetCurrentDirectory(nativePath);
if (result == 0) {
@@ -2929,6 +2932,12 @@ TclNativeCreateNativeRep(
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 = '\\';