diff options
Diffstat (limited to 'unix/tclUnixFile.c')
| -rw-r--r-- | unix/tclUnixFile.c | 72 | 
1 files changed, 44 insertions, 28 deletions
| diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index c213050..2cb0027 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -310,10 +310,9 @@ TclpMatchInDirectory(  	if (d == NULL) {  	    Tcl_DStringFree(&ds);  	    if (interp != NULL) { -		Tcl_ResetResult(interp); -		Tcl_AppendResult(interp, "couldn't read directory \"", -			Tcl_DStringValue(&dsOrig), "\": ", -			Tcl_PosixError(interp), NULL); +		Tcl_SetObjResult(interp, Tcl_ObjPrintf( +			"couldn't read directory \"%s\": %s", +			Tcl_DStringValue(&dsOrig), Tcl_PosixError(interp)));  	    }  	    Tcl_DStringFree(&dsOrig);  	    Tcl_DecrRefCount(fileNamePtr); @@ -471,7 +470,7 @@ NativeMatchType(  #ifndef MAC_OSX_TCL  	    || ((types->perm & TCL_GLOB_PERM_HIDDEN) &&  		(*nativeName != '.')) -#endif +#endif /* MAC_OSX_TCL */  		) {  	    return 0;  	} @@ -489,12 +488,10 @@ NativeMatchType(  		 * check that here:  		 */ -		if (types->type & TCL_GLOB_TYPE_LINK) { -		    if (TclOSlstat(nativeEntry, &buf) == 0) { -			if (S_ISLNK(buf.st_mode)) { -			    return 1; -			} -		    } +		if ((types->type & TCL_GLOB_TYPE_LINK) +			&& (TclOSlstat(nativeEntry, &buf) == 0) +			&& S_ISLNK(buf.st_mode)) { +		    return 1;  		}  		return 0;  	    } @@ -517,12 +514,10 @@ NativeMatchType(  	     */  	} else {  #ifdef S_ISLNK -	    if (types->type & TCL_GLOB_TYPE_LINK) { -		if (TclOSlstat(nativeEntry, &buf) == 0) { -		    if (S_ISLNK(buf.st_mode)) { -			goto filetypeOK; -		    } -		} +	    if ((types->type & TCL_GLOB_TYPE_LINK) +		    && (TclOSlstat(nativeEntry, &buf) == 0) +		    && S_ISLNK(buf.st_mode)) { +		goto filetypeOK;  	    }  #endif /* S_ISLNK */  	    return 0; @@ -718,9 +713,9 @@ TclpGetNativeCwd(      if (getcwd(buffer, MAXPATHLEN+1) == NULL) {		/* INTL: Native. */  	return NULL;      } -#endif +#endif /* USEGETWD */ -    if ((clientData == NULL) || strcmp(buffer, (const char*)clientData)) { +    if ((clientData == NULL) || strcmp(buffer, (const char *) clientData)) {  	char *newCd = ckalloc(strlen(buffer) + 1);  	strcpy(newCd, buffer); @@ -768,12 +763,12 @@ TclpGetCwd(      if (getwd(buffer) == NULL)				/* INTL: Native. */  #else      if (getcwd(buffer, MAXPATHLEN+1) == NULL)		/* INTL: Native. */ -#endif +#endif /* USEGETWD */      {  	if (interp != NULL) { -	    Tcl_AppendResult(interp, -		    "error getting working directory name: ", -		    Tcl_PosixError(interp), NULL); +	    Tcl_SetObjResult(interp, Tcl_ObjPrintf( +		    "error getting working directory name: %s", +		    Tcl_PosixError(interp)));  	}  	return NULL;      } @@ -824,7 +819,7 @@ TclpReadlink(      return Tcl_DStringValue(linkPtr);  #else      return NULL; -#endif +#endif /* !DJGPP */  }  /* @@ -858,7 +853,7 @@ TclpObjStat(  #ifdef S_IFLNK -Tcl_Obj* +Tcl_Obj *  TclpObjLink(      Tcl_Obj *pathPtr,      Tcl_Obj *toPtr, @@ -1110,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); @@ -1180,10 +1181,18 @@ TclpUtime(  {      return utime(Tcl_FSGetNativePath(pathPtr), tval);  } +  #ifdef __CYGWIN__ -int TclOSstat(const char *name, Tcl_StatBuf *statBuf) { + +int +TclOSstat( +    const char *name, +    void *cygstat) +{      struct stat buf; +    Tcl_StatBuf *statBuf = cygstat;      int result = stat(name, &buf); +      statBuf->st_mode = buf.st_mode;      statBuf->st_ino = buf.st_ino;      statBuf->st_dev = buf.st_dev; @@ -1197,9 +1206,16 @@ int TclOSstat(const char *name, Tcl_StatBuf *statBuf) {      statBuf->st_ctime = buf.st_ctime;      return result;  } -int TclOSlstat(const char *name, Tcl_StatBuf *statBuf) { + +int +TclOSlstat( +    const char *name, +    void *cygstat) +{      struct stat buf; +    Tcl_StatBuf *statBuf = cygstat;      int result = lstat(name, &buf); +      statBuf->st_mode = buf.st_mode;      statBuf->st_ino = buf.st_ino;      statBuf->st_dev = buf.st_dev; @@ -1213,7 +1229,7 @@ int TclOSlstat(const char *name, Tcl_StatBuf *statBuf) {      statBuf->st_ctime = buf.st_ctime;      return result;  } -#endif +#endif /* CYGWIN */  /*   * Local Variables: | 
