Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Use "strict" in almost all commands. Only "glob" and environment variables are left out. (Experimental) |
|---|---|
| Timelines: | family | ancestors | descendants | both | tip-657 |
| Files: | files | file ages | folders |
| SHA3-256: |
da536b980361149e6180ebcb7c06e44d |
| User & Date: | jan.nijtmans 2023-07-14 11:13:30.949 |
Context
|
2023-07-19
| ||
| 08:59 | Merge 9.0 check-in: 331a94f0b8 user: jan.nijtmans tags: tip-657 | |
|
2023-07-14
| ||
| 14:51 | First attempt to mix TIP's #657 and #671 check-in: 77d9664918 user: jan.nijtmans tags: tip-671 | |
| 11:13 | Use "strict" in almost all commands. Only "glob" and environment variables are left out. (Experiment... check-in: da536b9803 user: jan.nijtmans tags: tip-657 | |
| 06:31 | Rebase to 9.0 check-in: 0a52caf686 user: jan.nijtmans tags: tip-657 | |
Changes
Changes to generic/tclIOSock.c.
| ︙ | ︙ | |||
71 72 73 74 75 76 77 |
const char *native;
if (Tcl_GetInt(NULL, string, portPtr) != TCL_OK) {
/*
* Don't bother translating 'proto' to native.
*/
| | > > > > | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
const char *native;
if (Tcl_GetInt(NULL, string, portPtr) != TCL_OK) {
/*
* Don't bother translating 'proto' to native.
*/
if (Tcl_UtfToExternalDStringEx(interp, NULL, string, -1, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return TCL_ERROR;
}
native = Tcl_DStringValue(&ds);
sp = getservbyname(native, proto); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (sp != NULL) {
*portPtr = ntohs((unsigned short) sp->s_port);
return TCL_OK;
}
}
|
| ︙ | ︙ | |||
180 181 182 183 184 185 186 |
struct addrinfo *v6head = NULL, *v6ptr = NULL;
char *native = NULL, portbuf[TCL_INTEGER_SPACE], *portstring;
const char *family = NULL;
Tcl_DString ds;
int result;
if (host != NULL) {
| | > > > > | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
struct addrinfo *v6head = NULL, *v6ptr = NULL;
char *native = NULL, portbuf[TCL_INTEGER_SPACE], *portstring;
const char *family = NULL;
Tcl_DString ds;
int result;
if (host != NULL) {
if (Tcl_UtfToExternalDStringEx(interp, NULL, host, -1, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return 0;
}
native = Tcl_DStringValue(&ds);
}
/*
* Workaround for OSX's apparent inability to resolve "localhost", "0"
* when the loopback device is the only available network interface.
*/
|
| ︙ | ︙ |
Changes to generic/tclZipfs.c.
| ︙ | ︙ | |||
2537 2538 2539 2540 2541 2542 2543 |
}
/*
* Convert to encoded form. Note that we use strlen() here; if someone's
* crazy enough to embed NULs in filenames, they deserve what they get!
*/
| | > > > > | 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 |
}
/*
* Convert to encoded form. Note that we use strlen() here; if someone's
* crazy enough to embed NULs in filenames, they deserve what they get!
*/
if (Tcl_UtfToExternalDStringEx(interp, ZipFS.utf8, zpathTcl, TCL_INDEX_NONE, 0, &zpathDs, NULL) != TCL_OK) {
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
zpathExt = Tcl_DStringValue(&zpathDs);
zpathlen = strlen(zpathExt);
if (zpathlen + ZIP_CENTRAL_HEADER_LEN > bufsize) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"path too long for \"%s\"", TclGetString(pathObj)));
ZIPFS_ERROR_CODE(interp, "PATH_LEN");
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
|
| ︙ | ︙ | |||
3206 3207 3208 3209 3210 3211 3212 |
hPtr = Tcl_FindHashEntry(&fileHash, name);
if (!hPtr) {
continue;
}
z = (ZipEntry *) Tcl_GetHashValue(hPtr);
| | > > > > | 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 |
hPtr = Tcl_FindHashEntry(&fileHash, name);
if (!hPtr) {
continue;
}
z = (ZipEntry *) Tcl_GetHashValue(hPtr);
if (Tcl_UtfToExternalDStringEx(interp, ZipFS.utf8, z->name, TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) {
ret = TCL_ERROR;
goto done;
}
name = Tcl_DStringValue(&ds);
len = Tcl_DStringLength(&ds);
SerializeCentralDirectoryEntry(start, end, (unsigned char *) buf,
z, len);
if ((Tcl_Write(out, buf, ZIP_CENTRAL_HEADER_LEN)
!= ZIP_CENTRAL_HEADER_LEN)
|| (Tcl_Write(out, name, len) != len)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
|
| ︙ | ︙ |
Changes to tests/encoding.test.
| ︙ | ︙ | |||
573 574 575 576 577 578 579 |
test encoding-16.22 {Utf16ToUtfProc, strict, bug [db7a085bd9]} -body {
encoding convertfrom -profile strict utf-16le \x00\xD8
} -returnCodes 1 -result {unexpected byte sequence starting at index 0: '\x00'}
test encoding-16.23 {Utf16ToUtfProc, strict, bug [db7a085bd9]} -body {
encoding convertfrom -profile strict utf-16le \x00\xDC
} -returnCodes 1 -result {unexpected byte sequence starting at index 0: '\x00'}
test encoding-16.24 {Utf32ToUtfProc} -body {
| | | 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
test encoding-16.22 {Utf16ToUtfProc, strict, bug [db7a085bd9]} -body {
encoding convertfrom -profile strict utf-16le \x00\xD8
} -returnCodes 1 -result {unexpected byte sequence starting at index 0: '\x00'}
test encoding-16.23 {Utf16ToUtfProc, strict, bug [db7a085bd9]} -body {
encoding convertfrom -profile strict utf-16le \x00\xDC
} -returnCodes 1 -result {unexpected byte sequence starting at index 0: '\x00'}
test encoding-16.24 {Utf32ToUtfProc} -body {
encoding convertfrom -profile tcl8 utf-32 "\xFF\xFF\xFF\xFF"
} -result \uFFFD
test {encoding-16.25 strict} {Utf32ToUtfProc} -body {
encoding convertfrom -profile strict utf-32 "\x01\x00\x00\x01"
} -returnCodes 1 -result {unexpected byte sequence starting at index 0: '\x01'}
test {encoding-16.25 tcl8} {Utf32ToUtfProc} -body {
encoding convertfrom -profile tcl8 utf-32 "\x01\x00\x00\x01"
} -result \uFFFD
|
| ︙ | ︙ |
Changes to tests/utfext.test.
| ︙ | ︙ | |||
72 73 74 75 76 77 78 |
# Another bug - char limit not obeyed
# % set cv 2
# % testencoding Tcl_ExternalToUtf utf-8 abcdefgh {start end noterminate charlimit} {} 20 rv wv cv
# nospace {} abcÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
test TableToUtf-bug-5be203d6ca {Bug 5be203d6ca - truncated prefix in table encoding} -body {
set src \x82\x4F\x82\x50\x82
| | | | | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# Another bug - char limit not obeyed
# % set cv 2
# % testencoding Tcl_ExternalToUtf utf-8 abcdefgh {start end noterminate charlimit} {} 20 rv wv cv
# nospace {} abcÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
test TableToUtf-bug-5be203d6ca {Bug 5be203d6ca - truncated prefix in table encoding} -body {
set src \x82\x4F\x82\x50\x82
lassign [testencoding Tcl_ExternalToUtf shiftjis $src {start profiletcl8} 0 16 srcRead dstWritten charsWritten] buf
set result [list [testencoding Tcl_ExternalToUtf shiftjis $src {start profiletcl8} 0 16 srcRead dstWritten charsWritten] $srcRead $dstWritten $charsWritten]
lappend result {*}[list [testencoding Tcl_ExternalToUtf shiftjis [string range $src $srcRead end] {end profiletcl8} 0 10 srcRead dstWritten charsWritten] $srcRead $dstWritten $charsWritten]
} -result [list [list multibyte 0 \xEF\xBC\x90\xEF\xBC\x91\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF] 4 6 2 [list ok 0 \xC2\x82\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF] 1 2 1]
::tcltest::cleanupTests
return
# Local Variables:
|
| ︙ | ︙ |
Changes to unix/tclLoadDl.c.
| ︙ | ︙ | |||
104 105 106 107 108 109 110 | * string the user gave us which hopefully refers to a file on the * binary path. */ Tcl_DString ds; const char *fileName = TclGetString(pathPtr); | | > > > > | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
* string the user gave us which hopefully refers to a file on the
* binary path.
*/
Tcl_DString ds;
const char *fileName = TclGetString(pathPtr);
if (Tcl_UtfToExternalDStringEx(interp, NULL, fileName, TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return TCL_ERROR;
}
native = Tcl_DStringValue(&ds);
/*
* Use (RTLD_NOW|RTLD_LOCAL) as default, see [Bug #3216070]
*/
handle = dlopen(native, dlopenflags);
Tcl_DStringFree(&ds);
}
|
| ︙ | ︙ | |||
175 176 177 178 179 180 181 |
/*
* Some platforms still add an underscore to the beginning of symbol
* names. If we can't find a name without an underscore, try again with
* the underscore.
*/
| | > > > > | 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
/*
* Some platforms still add an underscore to the beginning of symbol
* names. If we can't find a name without an underscore, try again with
* the underscore.
*/
if (Tcl_UtfToExternalDStringEx(NULL, NULL, symbol, TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return NULL;
}
native = Tcl_DStringValue(&ds);
proc = dlsym(handle, native); /* INTL: Native. */
if (proc == NULL) {
Tcl_DStringInit(&newName);
TclDStringAppendLiteral(&newName, "_");
native = Tcl_DStringAppend(&newName, native, TCL_INDEX_NONE);
proc = dlsym(handle, native); /* INTL: Native. */
Tcl_DStringFree(&newName);
|
| ︙ | ︙ |
Changes to unix/tclUnixFCmd.c.
| ︙ | ︙ | |||
758 759 760 761 762 763 764 |
{
Tcl_DString ds;
Tcl_DString srcString, dstString;
int ret;
Tcl_Obj *transPtr;
transPtr = Tcl_FSGetTranslatedPath(NULL,srcPathPtr);
| | | > > > | | | | | | > > | > > > | | > | | < < | 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
{
Tcl_DString ds;
Tcl_DString srcString, dstString;
int ret;
Tcl_Obj *transPtr;
transPtr = Tcl_FSGetTranslatedPath(NULL,srcPathPtr);
ret = Tcl_UtfToExternalDStringEx(NULL, NULL,
(transPtr != NULL ? TclGetString(transPtr) : NULL),
-1, 0, &srcString, NULL);
if (transPtr != NULL) {
Tcl_DecrRefCount(transPtr);
}
if (ret != TCL_OK) {
*errorPtr = srcPathPtr;
} else {
transPtr = Tcl_FSGetTranslatedPath(NULL,destPathPtr);
ret = Tcl_UtfToExternalDStringEx(NULL, NULL,
(transPtr != NULL ? TclGetString(transPtr) : NULL),
-1, TCL_ENCODING_PROFILE_TCL8, &dstString, NULL);
if (transPtr != NULL) {
Tcl_DecrRefCount(transPtr);
}
if (ret != TCL_OK) {
*errorPtr = destPathPtr;
} else {
ret = TraverseUnixTree(TraversalCopy, &srcString, &dstString, &ds, 0);
/* Note above call only sets ds on error */
if (ret != TCL_OK) {
*errorPtr = Tcl_DStringToObj(&ds);
}
Tcl_DStringFree(&dstString);
}
Tcl_DStringFree(&srcString);
}
if (ret != TCL_OK) {
Tcl_IncrRefCount(*errorPtr);
}
return ret;
}
/*
*---------------------------------------------------------------------------
|
| ︙ | ︙ | |||
822 823 824 825 826 827 828 |
Tcl_Obj **errorPtr)
{
Tcl_DString ds;
Tcl_DString pathString;
int ret;
Tcl_Obj *transPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr);
| | > > > | | > > > | > > < < | 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 |
Tcl_Obj **errorPtr)
{
Tcl_DString ds;
Tcl_DString pathString;
int ret;
Tcl_Obj *transPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr);
ret = Tcl_UtfToExternalDStringEx(NULL, NULL,
(transPtr != NULL ? TclGetString(transPtr) : NULL),
-1, TCL_ENCODING_PROFILE_TCL8, &pathString, NULL);
if (transPtr != NULL) {
Tcl_DecrRefCount(transPtr);
}
if (ret != TCL_OK) {
*errorPtr = pathPtr;
} else {
ret = DoRemoveDirectory(&pathString, recursive, &ds);
Tcl_DStringFree(&pathString);
/* Note above call only sets ds on error */
if (ret != TCL_OK) {
*errorPtr = Tcl_DStringToObj(&ds);
}
}
if (ret != TCL_OK) {
Tcl_IncrRefCount(*errorPtr);
}
return ret;
}
static int
DoRemoveDirectory(
|
| ︙ | ︙ | |||
882 883 884 885 886 887 888 |
if (errno == ENOTEMPTY) {
errno = EEXIST;
}
result = TCL_OK;
if ((errno != EEXIST) || (recursive == 0)) {
if (errorPtr != NULL) {
| | | 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 |
if (errno == ENOTEMPTY) {
errno = EEXIST;
}
result = TCL_OK;
if ((errno != EEXIST) || (recursive == 0)) {
if (errorPtr != NULL) {
Tcl_ExternalToUtfDStringEx(NULL, NULL, path, TCL_INDEX_NONE, 0, errorPtr, NULL);
}
result = TCL_ERROR;
}
/*
* The directory is nonempty, but the recursive flag has been specified,
* so we recursively remove all the files in the directory.
|
| ︙ | ︙ | |||
1131 1132 1133 1134 1135 1136 1137 |
}
}
#endif /* !HAVE_FTS */
end:
if (errfile != NULL) {
if (errorPtr != NULL) {
| | | 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 |
}
}
#endif /* !HAVE_FTS */
end:
if (errfile != NULL) {
if (errorPtr != NULL) {
Tcl_ExternalToUtfDStringEx(NULL, NULL, errfile, TCL_INDEX_NONE, 0, errorPtr, NULL);
}
result = TCL_ERROR;
}
#ifdef HAVE_FTS
if (fts != NULL) {
fts_close(fts);
}
|
| ︙ | ︙ | |||
1202 1203 1204 1205 1206 1207 1208 |
/*
* There shouldn't be a problem with src, because we already checked it to
* get here.
*/
if (errorPtr != NULL) {
Tcl_ExternalToUtfDStringEx(NULL, NULL, Tcl_DStringValue(dstPtr),
| | | 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
/*
* There shouldn't be a problem with src, because we already checked it to
* get here.
*/
if (errorPtr != NULL) {
Tcl_ExternalToUtfDStringEx(NULL, NULL, Tcl_DStringValue(dstPtr),
Tcl_DStringLength(dstPtr), 0, errorPtr, NULL);
}
return TCL_ERROR;
}
/*
*---------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
1253 1254 1255 1256 1257 1258 1259 |
if (DoRemoveDirectory(srcPtr, 0, NULL) == 0) {
return TCL_OK;
}
break;
}
if (errorPtr != NULL) {
Tcl_ExternalToUtfDStringEx(NULL, NULL, Tcl_DStringValue(srcPtr),
| | | 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 |
if (DoRemoveDirectory(srcPtr, 0, NULL) == 0) {
return TCL_OK;
}
break;
}
if (errorPtr != NULL) {
Tcl_ExternalToUtfDStringEx(NULL, NULL, Tcl_DStringValue(srcPtr),
Tcl_DStringLength(srcPtr), 0, errorPtr, NULL);
}
return TCL_ERROR;
}
/*
*---------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
1420 1421 1422 1423 1424 1425 1426 |
pwPtr = TclpGetPwUid(statBuf.st_uid);
if (pwPtr == NULL) {
TclNewIntObj(*attributePtrPtr, statBuf.st_uid);
} else {
Tcl_DString ds;
| | | 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 |
pwPtr = TclpGetPwUid(statBuf.st_uid);
if (pwPtr == NULL) {
TclNewIntObj(*attributePtrPtr, statBuf.st_uid);
} else {
Tcl_DString ds;
Tcl_ExternalToUtfDStringEx(NULL, NULL, pwPtr->pw_name, TCL_INDEX_NONE, 0, &ds, NULL);
*attributePtrPtr = Tcl_DStringToObj(&ds);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
1504 1505 1506 1507 1508 1509 1510 | Tcl_DString ds; struct group *groupPtr = NULL; const char *string; Tcl_Size length; string = Tcl_GetStringFromObj(attributePtr, &length); | | > > > > | 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 |
Tcl_DString ds;
struct group *groupPtr = NULL;
const char *string;
Tcl_Size length;
string = Tcl_GetStringFromObj(attributePtr, &length);
if (Tcl_UtfToExternalDStringEx(interp, NULL, string, length, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return TCL_ERROR;
}
native = Tcl_DStringValue(&ds);
groupPtr = TclpGetGrNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (groupPtr == NULL) {
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"could not set group for file \"%s\":"
|
| ︙ | ︙ | |||
1571 1572 1573 1574 1575 1576 1577 | Tcl_DString ds; struct passwd *pwPtr = NULL; const char *string; Tcl_Size length; string = Tcl_GetStringFromObj(attributePtr, &length); | | > > > > | 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 |
Tcl_DString ds;
struct passwd *pwPtr = NULL;
const char *string;
Tcl_Size length;
string = Tcl_GetStringFromObj(attributePtr, &length);
if (Tcl_UtfToExternalDStringEx(interp, NULL, string, length, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return TCL_ERROR;
}
native = Tcl_DStringValue(&ds);
pwPtr = TclpGetPwNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (pwPtr == NULL) {
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"could not set owner for file \"%s\":"
|
| ︙ | ︙ | |||
1931 1932 1933 1934 1935 1936 1937 | * Side effects: * *--------------------------------------------------------------------------- */ int TclpObjNormalizePath( | | | 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 |
* Side effects:
*
*---------------------------------------------------------------------------
*/
int
TclpObjNormalizePath(
Tcl_Interp *interp,
Tcl_Obj *pathPtr, /* An unshared object containing the path to
* normalize. */
int nextCheckpoint) /* offset to start at in pathPtr. Must either
* be 0 or the offset of a directory separator
* at the end of a path part that is already
* normalized. I.e. this is not the index of
* the byte just after the separator. */
|
| ︙ | ︙ | |||
1965 1966 1967 1968 1969 1970 1971 |
/*
* Try to get the entire path in one go
*/
const char *lastDir = strrchr(currentPathEndPosition, '/');
if (lastDir != NULL) {
| | | > > > > | 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 |
/*
* Try to get the entire path in one go
*/
const char *lastDir = strrchr(currentPathEndPosition, '/');
if (lastDir != NULL) {
if (Tcl_UtfToExternalDStringEx(interp, NULL, path,
lastDir-path, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return -1;
}
nativePath = Tcl_DStringValue(&ds);
if (Realpath(nativePath, normPath) != NULL) {
if (*nativePath != '/' && *normPath == '/') {
/*
* realpath transformed a relative path into an
* absolute path. Fall back to the long way.
*/
|
| ︙ | ︙ | |||
2001 2002 2003 2004 2005 2006 2007 |
if ((cur == '/') && (path != currentPathEndPosition)) {
/*
* Reached directory separator.
*/
int accessOk;
| | | > > > > | 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 |
if ((cur == '/') && (path != currentPathEndPosition)) {
/*
* Reached directory separator.
*/
int accessOk;
if (Tcl_UtfToExternalDStringEx(interp, NULL, path,
currentPathEndPosition - path, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return -1;
}
nativePath = Tcl_DStringValue(&ds);
accessOk = access(nativePath, F_OK);
Tcl_DStringFree(&ds);
if (accessOk != 0) {
/*
* File doesn't exist.
*/
|
| ︙ | ︙ | |||
2046 2047 2048 2049 2050 2051 2052 | * 'Realpath' transforms an empty string into the normalized pwd, * which is the wrong answer. */ return 0; } | | > > > > | 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 |
* 'Realpath' transforms an empty string into the normalized pwd,
* which is the wrong answer.
*/
return 0;
}
if (Tcl_UtfToExternalDStringEx(interp, NULL, path,nextCheckpoint, 0, &ds, NULL)) {
Tcl_DStringFree(&ds);
return -1;
}
nativePath = Tcl_DStringValue(&ds);
if (Realpath(nativePath, normPath) != NULL) {
Tcl_Size newNormLen;
wholeStringOk:
newNormLen = strlen(normPath);
if ((newNormLen == Tcl_DStringLength(&ds))
&& (strcmp(normPath, nativePath) == 0)) {
|
| ︙ | ︙ | |||
2082 2083 2084 2085 2086 2087 2088 | } /* * Free the original path and replace it with the normalized path. */ Tcl_DStringFree(&ds); | | | 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 |
}
/*
* Free the original path and replace it with the normalized path.
*/
Tcl_DStringFree(&ds);
Tcl_ExternalToUtfDStringEx(NULL, NULL, normPath, newNormLen, 0, &ds, NULL);
if (path[nextCheckpoint] != '\0') {
/*
* Append the remaining path components.
*/
int normLen = Tcl_DStringLength(&ds);
|
| ︙ | ︙ | |||
2170 2171 2172 2173 2174 2175 2176 |
{
Tcl_DString templ, tmp;
const char *string;
int fd;
Tcl_Size length;
/*
| | | > > | > > > | > > > | | > > > | 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 |
{
Tcl_DString templ, tmp;
const char *string;
int fd;
Tcl_Size length;
/*
* We should also check against making more than TMP_MAX of these.
*/
if (dirObj) {
string = Tcl_GetStringFromObj(dirObj, &length);
if (Tcl_UtfToExternalDStringEx(NULL, NULL, string, length, 0, &templ, NULL) != TCL_OK) {
return -1;
}
} else {
Tcl_DStringInit(&templ);
Tcl_DStringAppend(&templ, DefaultTempDir(), TCL_INDEX_NONE); /* INTL: native */
}
TclDStringAppendLiteral(&templ, "/");
if (basenameObj) {
string = Tcl_GetStringFromObj(basenameObj, &length);
if (Tcl_UtfToExternalDStringEx(NULL, NULL, string, length, 0, &tmp, NULL) != TCL_OK) {
Tcl_DStringFree(&tmp);
return -1;
}
TclDStringAppendDString(&templ, &tmp);
Tcl_DStringFree(&tmp);
} else {
TclDStringAppendLiteral(&templ, "tcl");
}
TclDStringAppendLiteral(&templ, "_XXXXXX");
#ifdef HAVE_MKSTEMPS
if (extensionObj) {
string = Tcl_GetStringFromObj(extensionObj, &length);
if (Tcl_UtfToExternalDStringEx(NULL, NULL, string, length, 0, &tmp, NULL) != TCL_OK) {
Tcl_DStringFree(&templ);
return -1;
}
TclDStringAppendDString(&templ, &tmp);
fd = mkstemps(Tcl_DStringValue(&templ), Tcl_DStringLength(&tmp));
Tcl_DStringFree(&tmp);
} else
#endif
{
fd = mkstemp(Tcl_DStringValue(&templ));
}
if (fd == -1) {
Tcl_DStringFree(&templ);
return -1;
}
if (resultingNameObj) {
if (Tcl_ExternalToUtfDStringEx(NULL, NULL, Tcl_DStringValue(&templ),
Tcl_DStringLength(&templ), 0, &tmp, NULL) != TCL_OK) {
Tcl_DStringFree(&templ);
return -1;
}
Tcl_SetStringObj(resultingNameObj, Tcl_DStringValue(&tmp),
Tcl_DStringLength(&tmp));
Tcl_DStringFree(&tmp);
} else {
/*
* Try to delete the file immediately since we're not reporting the
* name to anyone. Note that we're *not* handling any errors from
|
| ︙ | ︙ | |||
2300 2301 2302 2303 2304 2305 2306 |
/*
* Build the template in writable memory from the user-supplied pieces and
* some defaults.
*/
if (dirObj) {
string = TclGetString(dirObj);
| | > > | > > > | 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 |
/*
* Build the template in writable memory from the user-supplied pieces and
* some defaults.
*/
if (dirObj) {
string = TclGetString(dirObj);
if (Tcl_UtfToExternalDStringEx(NULL, NULL, string, dirObj->length, 0, &templ, NULL) != TCL_OK) {
return NULL;
}
} else {
Tcl_DStringInit(&templ);
Tcl_DStringAppend(&templ, DefaultTempDir(), TCL_INDEX_NONE); /* INTL: native */
}
if (Tcl_DStringValue(&templ)[Tcl_DStringLength(&templ) - 1] != '/') {
TclDStringAppendLiteral(&templ, "/");
}
if (basenameObj) {
string = TclGetString(basenameObj);
if (basenameObj->length) {
if (Tcl_UtfToExternalDStringEx(NULL, NULL, string, basenameObj->length, 0, &tmp, NULL) != TCL_OK) {
Tcl_DStringFree(&templ);
return NULL;
}
TclDStringAppendDString(&templ, &tmp);
Tcl_DStringFree(&tmp);
} else {
TclDStringAppendLiteral(&templ, DEFAULT_TEMP_DIR_PREFIX);
}
} else {
TclDStringAppendLiteral(&templ, DEFAULT_TEMP_DIR_PREFIX);
|
| ︙ | ︙ | |||
2338 2339 2340 2341 2342 2343 2344 |
return NULL;
}
/*
* The template has been updated. Tell the caller what it was.
*/
| | | > > > | 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 |
return NULL;
}
/*
* The template has been updated. Tell the caller what it was.
*/
if (Tcl_ExternalToUtfDStringEx(NULL, NULL, Tcl_DStringValue(&templ),
Tcl_DStringLength(&templ), 0, &tmp, NULL) != TCL_OK) {
Tcl_DStringFree(&templ);
return NULL;
}
Tcl_DStringFree(&templ);
return Tcl_DStringToObj(&tmp);
}
#if defined(__CYGWIN__)
static void
|
| ︙ | ︙ |
Changes to unix/tclUnixFile.c.
| ︙ | ︙ | |||
304 305 306 307 308 309 310 | } } /* * Now open the directory for reading and iterate over the contents. */ | | > > > > > > | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
}
}
/*
* Now open the directory for reading and iterate over the contents.
*/
if (Tcl_UtfToExternalDStringEx(interp, NULL, dirName, TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&dsOrig);
Tcl_DStringFree(&ds);
Tcl_DecrRefCount(fileNamePtr);
return TCL_ERROR;
}
native = Tcl_DStringValue(&ds);
if ((TclOSstat(native, &statBuf) != 0) /* INTL: Native. */
|| !S_ISDIR(statBuf.st_mode)) {
Tcl_DStringFree(&dsOrig);
Tcl_DStringFree(&ds);
Tcl_DecrRefCount(fileNamePtr);
return TCL_OK;
|
| ︙ | ︙ | |||
368 369 370 371 372 373 374 | } /* * Now check to see if the file matches, according to both type * and pattern. If so, add the file to the result. */ | | > > > > | | 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
}
/*
* Now check to see if the file matches, according to both type
* and pattern. If so, add the file to the result.
*/
if (Tcl_ExternalToUtfDStringEx(interp, NULL, entryPtr->d_name, TCL_INDEX_NONE,
0, &utfDs, NULL) != TCL_OK) {
matchResult = -1;
break;
}
utfname = Tcl_DStringValue(&utfDs);
if (Tcl_StringCaseMatch(utfname, pattern, 0)) {
int typeOk = 1;
if (types != NULL) {
Tcl_DStringSetLength(&ds, nativeDirLen);
native = Tcl_DStringAppend(&ds, entryPtr->d_name, TCL_INDEX_NONE);
matchResult = NativeMatchType(interp, native,
|
| ︙ | ︙ | |||
595 596 597 598 599 600 601 |
TclpGetUserHome(
const char *name, /* User name for desired home directory. */
Tcl_DString *bufferPtr) /* Uninitialized or free DString filled with
* name of user's home directory. */
{
struct passwd *pwPtr;
Tcl_DString ds;
| | > > > > > > | > > > > | 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
TclpGetUserHome(
const char *name, /* User name for desired home directory. */
Tcl_DString *bufferPtr) /* Uninitialized or free DString filled with
* name of user's home directory. */
{
struct passwd *pwPtr;
Tcl_DString ds;
const char *native;
if (Tcl_UtfToExternalDStringEx(NULL, NULL, name, TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return NULL;
}
native = Tcl_DStringValue(&ds);
pwPtr = TclpGetPwNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (pwPtr == NULL) {
return NULL;
}
if (Tcl_ExternalToUtfDStringEx(NULL, NULL, pwPtr->pw_dir, TCL_INDEX_NONE, 0, bufferPtr, NULL) != TCL_OK) {
return NULL;
} else {
return Tcl_DStringValue(bufferPtr);
}
}
/*
*---------------------------------------------------------------------------
*
* TclpObjAccess --
*
|
| ︙ | ︙ | |||
781 782 783 784 785 786 787 |
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"error getting working directory name: %s",
Tcl_PosixError(interp)));
}
return NULL;
}
| | > > > | 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 |
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"error getting working directory name: %s",
Tcl_PosixError(interp)));
}
return NULL;
}
if (Tcl_ExternalToUtfDStringEx(interp, NULL, buffer, TCL_INDEX_NONE, 0, bufferPtr, NULL) != TCL_OK) {
return NULL;
}
return Tcl_DStringValue(bufferPtr);
}
/*
*---------------------------------------------------------------------------
*
* TclpReadlink --
*
|
| ︙ | ︙ | |||
812 813 814 815 816 817 818 |
TclpReadlink(
const char *path, /* Path of file to readlink (UTF-8). */
Tcl_DString *linkPtr) /* Uninitialized or free DString filled with
* contents of link (UTF-8). */
{
#ifndef DJGPP
char link[MAXPATHLEN];
| | | > > > > | | > > | < | 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
TclpReadlink(
const char *path, /* Path of file to readlink (UTF-8). */
Tcl_DString *linkPtr) /* Uninitialized or free DString filled with
* contents of link (UTF-8). */
{
#ifndef DJGPP
char link[MAXPATHLEN];
Tcl_Size length;
const char *native;
Tcl_DString ds;
if (Tcl_UtfToExternalDStringEx(NULL, NULL, path, TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return NULL;
}
native = Tcl_DStringValue(&ds);
length = readlink(native, link, sizeof(link)); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (length < 0) {
return NULL;
}
if (Tcl_ExternalToUtfDStringEx(NULL, NULL, link, length, 0, linkPtr, NULL) == TCL_OK) {
return Tcl_DStringValue(linkPtr);
}
#endif /* !DJGPP */
return NULL;
}
/*
*----------------------------------------------------------------------
*
* TclpObjStat --
*
|
| ︙ | ︙ | |||
958 959 960 961 962 963 964 |
*/
transPtr = Tcl_FSGetTranslatedPath(NULL, toPtr);
if (transPtr == NULL) {
return NULL;
}
target = Tcl_GetStringFromObj(transPtr, &length);
| | > > > > | 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 |
*/
transPtr = Tcl_FSGetTranslatedPath(NULL, toPtr);
if (transPtr == NULL) {
return NULL;
}
target = Tcl_GetStringFromObj(transPtr, &length);
if (Tcl_UtfToExternalDStringEx(NULL, NULL, target, length, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return NULL;
}
target = Tcl_DStringValue(&ds);
Tcl_DecrRefCount(transPtr);
if (symlink(target, src) != 0) {
toPtr = NULL;
}
Tcl_DStringFree(&ds);
} else if (linkAction & TCL_CREATE_HARD_LINK) {
|
| ︙ | ︙ | |||
993 994 995 996 997 998 999 |
Tcl_DecrRefCount(transPtr);
length = readlink((const char *)Tcl_FSGetNativePath(pathPtr), link, sizeof(link));
if (length < 0) {
return NULL;
}
| | > > | 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 |
Tcl_DecrRefCount(transPtr);
length = readlink((const char *)Tcl_FSGetNativePath(pathPtr), link, sizeof(link));
if (length < 0) {
return NULL;
}
if (Tcl_ExternalToUtfDStringEx(NULL, NULL, link, (size_t)length, 0, &ds, NULL) != TCL_OK) {
return NULL;
}
linkPtr = Tcl_DStringToObj(&ds);
Tcl_IncrRefCount(linkPtr);
return linkPtr;
}
}
#endif /* S_IFLNK */
|
| ︙ | ︙ | |||
1058 1059 1060 1061 1062 1063 1064 |
Tcl_Obj *
TclpNativeToNormalized(
void *clientData)
{
Tcl_DString ds;
| | | 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
Tcl_Obj *
TclpNativeToNormalized(
void *clientData)
{
Tcl_DString ds;
Tcl_ExternalToUtfDStringEx(NULL, NULL, (const char *) clientData, TCL_INDEX_NONE, 0, &ds, NULL);
return Tcl_DStringToObj(&ds);
}
/*
*---------------------------------------------------------------------------
*
* TclNativeCreateNativeRep --
|
| ︙ | ︙ | |||
1112 1113 1114 1115 1116 1117 1118 |
if (validPathPtr == NULL) {
return NULL;
}
Tcl_IncrRefCount(validPathPtr);
}
str = Tcl_GetStringFromObj(validPathPtr, &len);
| | > > > > | 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 |
if (validPathPtr == NULL) {
return NULL;
}
Tcl_IncrRefCount(validPathPtr);
}
str = Tcl_GetStringFromObj(validPathPtr, &len);
if (Tcl_UtfToExternalDStringEx(NULL, NULL, str, len, 0, &ds, NULL) != TCL_OK) {
Tcl_DecrRefCount(validPathPtr);
Tcl_DStringFree(&ds);
return NULL;
}
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;
}
|
| ︙ | ︙ |
Changes to unix/tclUnixPipe.c.
| ︙ | ︙ | |||
137 138 139 140 141 142 143 |
const char *fname, /* The name of the file to open. */
int mode) /* In what mode to open the file? */
{
int fd;
const char *native;
Tcl_DString ds;
| | > > > > | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
const char *fname, /* The name of the file to open. */
int mode) /* In what mode to open the file? */
{
int fd;
const char *native;
Tcl_DString ds;
if (Tcl_UtfToExternalDStringEx(NULL, NULL, fname, TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return NULL;
}
native = Tcl_DStringValue(&ds);
fd = TclOSopen(native, mode, 0666); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (fd != -1) {
fcntl(fd, F_SETFD, FD_CLOEXEC);
/*
* If the file is being opened for writing, seek to the end so we can
|
| ︙ | ︙ | |||
194 195 196 197 198 199 200 |
return NULL;
}
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (contents != NULL) {
Tcl_DString dstring;
char *native;
| | > > > > > | 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
return NULL;
}
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (contents != NULL) {
Tcl_DString dstring;
char *native;
if (Tcl_UtfToExternalDStringEx(NULL, NULL, contents, TCL_INDEX_NONE, 0, &dstring, NULL) != TCL_OK) {
close(fd);
Tcl_DStringFree(&dstring);
return NULL;
}
native = Tcl_DStringValue(&dstring);
if (write(fd, native, Tcl_DStringLength(&dstring)) == -1) {
close(fd);
Tcl_DStringFree(&dstring);
return NULL;
}
Tcl_DStringFree(&dstring);
TclOSseek(fd, 0, SEEK_SET);
|
| ︙ | ︙ | |||
433 434 435 436 437 438 439 |
* deallocated later
*/
dsArray = (Tcl_DString *)TclStackAlloc(interp, argc * sizeof(Tcl_DString));
newArgv = (char **)TclStackAlloc(interp, (argc+1) * sizeof(char *));
newArgv[argc] = NULL;
for (i = 0; i < argc; i++) {
| | > > > > > > > > | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
* deallocated later
*/
dsArray = (Tcl_DString *)TclStackAlloc(interp, argc * sizeof(Tcl_DString));
newArgv = (char **)TclStackAlloc(interp, (argc+1) * sizeof(char *));
newArgv[argc] = NULL;
for (i = 0; i < argc; i++) {
if (Tcl_UtfToExternalDStringEx(interp, NULL, argv[i], TCL_INDEX_NONE, 0, &dsArray[i], NULL) != TCL_OK) {
while (i-- > 0) {
Tcl_DStringFree(&dsArray[i]);
}
TclStackFree(interp, newArgv);
TclStackFree(interp, dsArray);
goto error;
}
newArgv[i] = Tcl_DStringValue(&dsArray[i]);
}
#ifdef USE_VFORK
/*
* After vfork(), do not call code in the child that changes global state,
* because it is using the parent's memory space at that point and writes
* might corrupt the parent: so ensure standard channels are initialized
|
| ︙ | ︙ |
Changes to win/tclWinPipe.c.
| ︙ | ︙ | |||
647 648 649 650 651 652 653 |
*/
TclFile
TclpCreateTempFile(
const char *contents) /* String to write into temp file, or NULL. */
{
WCHAR name[MAX_PATH];
| | | 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
*/
TclFile
TclpCreateTempFile(
const char *contents) /* String to write into temp file, or NULL. */
{
WCHAR name[MAX_PATH];
const char *native = NULL;
Tcl_DString dstring;
HANDLE handle;
if (TempFileName(name) == 0) {
return NULL;
}
|
| ︙ | ︙ | |||
675 676 677 678 679 680 681 | const char *p; int toCopy; /* * Convert the contents from UTF to native encoding */ | | > > > | 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
const char *p;
int toCopy;
/*
* Convert the contents from UTF to native encoding
*/
if (Tcl_UtfToExternalDStringEx(NULL, NULL, contents, TCL_INDEX_NONE, 0, &dstring, NULL) != TCL_OK) {
goto error;
}
native = Tcl_DStringValue(&dstring);
toCopy = Tcl_DStringLength(&dstring);
for (p = native; toCopy > 0; p++, toCopy--) {
if (*p == '\n') {
length = p - native;
if (length > 0) {
if (!WriteFile(handle, native, length, &result, NULL)) {
|
| ︙ | ︙ | |||
715 716 717 718 719 720 721 |
* Free the native representation of the contents if necessary.
*/
if (contents != NULL) {
Tcl_DStringFree(&dstring);
}
| > | > | 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
* Free the native representation of the contents if necessary.
*/
if (contents != NULL) {
Tcl_DStringFree(&dstring);
}
if (native != NULL) {
Tcl_WinConvertError(GetLastError());
}
CloseHandle(handle);
DeleteFileW(name);
return NULL;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ |