diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | unix/tclUnixFCmd.c | 113 |
2 files changed, 74 insertions, 44 deletions
@@ -1,3 +1,8 @@ +2004-09-03 Donal K. Fellows <donal.k.fellows@man.ac.uk> + + * unix/tclUnixFCmd.c: Stop NULL interp arguments from triggering a + crash when an error happens. [Bug 1020538] + 2004-09-02 Donal K. Fellows <donal.k.fellows@man.ac.uk> * doc/lsearch.n: Clarified meaning of -dictionary. [Bug 759545] diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c index 430c932..d6282d1 100644 --- a/unix/tclUnixFCmd.c +++ b/unix/tclUnixFCmd.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixFCmd.c,v 1.37 2004/04/26 15:51:20 dgp Exp $ + * RCS: @(#) $Id: tclUnixFCmd.c,v 1.38 2004/09/03 10:59:43 dkf Exp $ * * Portions of this code were derived from NetBSD source code which has * the following copyright notice: @@ -1173,9 +1173,11 @@ GetGroupAttribute(interp, objIndex, fileName, attributePtrPtr) result = TclpObjStat(fileName, &statBuf); if (result != 0) { - Tcl_AppendResult(interp, "could not read \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not read \"", + Tcl_GetString(fileName), "\": ", + Tcl_PosixError(interp), (char *) NULL); + } return TCL_ERROR; } @@ -1225,9 +1227,11 @@ GetOwnerAttribute(interp, objIndex, fileName, attributePtrPtr) result = TclpObjStat(fileName, &statBuf); if (result != 0) { - Tcl_AppendResult(interp, "could not read \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not read \"", + Tcl_GetString(fileName), "\": ", + Tcl_PosixError(interp), (char *) NULL); + } return TCL_ERROR; } @@ -1277,9 +1281,11 @@ GetPermissionsAttribute(interp, objIndex, fileName, attributePtrPtr) result = TclpObjStat(fileName, &statBuf); if (result != 0) { - Tcl_AppendResult(interp, "could not read \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not read \"", + Tcl_GetString(fileName), "\": ", + Tcl_PosixError(interp), (char *) NULL); + } return TCL_ERROR; } @@ -1331,10 +1337,12 @@ SetGroupAttribute(interp, objIndex, fileName, attributePtr) if (groupPtr == NULL) { endgrent(); - Tcl_AppendResult(interp, "could not set group for file \"", - Tcl_GetString(fileName), "\": group \"", - string, "\" does not exist", - (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not set group for file \"", + Tcl_GetString(fileName), "\": group \"", + string, "\" does not exist", + (char *) NULL); + } return TCL_ERROR; } gid = groupPtr->gr_gid; @@ -1345,9 +1353,11 @@ SetGroupAttribute(interp, objIndex, fileName, attributePtr) endgrent(); if (result != 0) { - Tcl_AppendResult(interp, "could not set group for file \"", - Tcl_GetString(fileName), "\": ", Tcl_PosixError(interp), - (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not set group for file \"", + Tcl_GetString(fileName), "\": ", Tcl_PosixError(interp), + (char *) NULL); + } return TCL_ERROR; } return TCL_OK; @@ -1393,10 +1403,11 @@ SetOwnerAttribute(interp, objIndex, fileName, attributePtr) Tcl_DStringFree(&ds); if (pwPtr == NULL) { - Tcl_AppendResult(interp, "could not set owner for file \"", - Tcl_GetString(fileName), "\": user \"", - string, "\" does not exist", - (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not set owner for file \"", + Tcl_GetString(fileName), "\": user \"", string, + "\" does not exist", (char *) NULL); + } return TCL_ERROR; } uid = pwPtr->pw_uid; @@ -1406,9 +1417,11 @@ SetOwnerAttribute(interp, objIndex, fileName, attributePtr) result = chown(native, (uid_t) uid, (gid_t) -1); /* INTL: Native. */ if (result != 0) { - Tcl_AppendResult(interp, "could not set owner for file \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not set owner for file \"", + Tcl_GetString(fileName), "\": ", Tcl_PosixError(interp), + (char *) NULL); + } return TCL_ERROR; } return TCL_OK; @@ -1459,17 +1472,21 @@ SetPermissionsAttribute(interp, objIndex, fileName, attributePtr) */ result = TclpObjStat(fileName, &buf); if (result != 0) { - Tcl_AppendResult(interp, "could not read \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not read \"", + Tcl_GetString(fileName), "\": ", + Tcl_PosixError(interp), (char *) NULL); + } return TCL_ERROR; } newMode = (mode_t) (buf.st_mode & 0x00007FFF); if (GetModeFromPermString(NULL, modeStringPtr, &newMode) != TCL_OK) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), - "unknown permission string format \"", - modeStringPtr, "\"", (char *) NULL); + if (interp != NULL) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "unknown permission string format \"", + modeStringPtr, "\"", (char *) NULL); + } return TCL_ERROR; } } @@ -1477,10 +1494,12 @@ SetPermissionsAttribute(interp, objIndex, fileName, attributePtr) native = Tcl_FSGetNativePath(fileName); result = chmod(native, newMode); /* INTL: Native. */ if (result != 0) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), - "could not set permissions for file \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "could not set permissions for file \"", + Tcl_GetString(fileName), "\": ", + Tcl_PosixError(interp), (char *) NULL); + } return TCL_ERROR; } return TCL_OK; @@ -1889,9 +1908,11 @@ GetReadOnlyAttribute(interp, objIndex, fileName, attributePtrPtr) result = TclpObjStat(fileName, &statBuf); if (result != 0) { - Tcl_AppendResult(interp, "could not read \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not read \"", + Tcl_GetString(fileName), "\": ", Tcl_PosixError(interp), + (char *) NULL); + } return TCL_ERROR; } @@ -1935,9 +1956,11 @@ SetReadOnlyAttribute(interp, objIndex, fileName, attributePtr) result = TclpObjStat(fileName, &statBuf); if (result != 0) { - Tcl_AppendResult(interp, "could not read \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendResult(interp, "could not read \"", + Tcl_GetString(fileName), "\": ", Tcl_PosixError(interp), + (char *) NULL); + } return TCL_ERROR; } @@ -1950,10 +1973,12 @@ SetReadOnlyAttribute(interp, objIndex, fileName, attributePtr) native = Tcl_FSGetNativePath(fileName); result = chflags(native, statBuf.st_flags); /* INTL: Native. */ if (result != 0) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), - "could not set flags for file \"", - Tcl_GetString(fileName), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "could not set flags for file \"", + Tcl_GetString(fileName), "\": ", Tcl_PosixError(interp), + (char *) NULL); + } return TCL_ERROR; } return TCL_OK; |