Tcl Source Code

Check-in [b6d467a174]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

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

Overview
Comment:merge fix for [92564326a98b5510] from 8.5
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core-8-6-branch
Files: files | file ages | folders
SHA3-256: b6d467a174515ff7a35109ae73a3dd89ca3010a1d39adcb110942ad131aaf38f
User & Date: sebres 2018-05-08 09:56:35
Context
2018-05-08
10:16
prevents UB/segfault by unexpected return-code (not -1/0/1) and avoid warnings like: tclCmdMZ.c:28... check-in: cb1fc580ea user: sebres tags: core-8-6-branch
09:56
merge fix for [92564326a98b5510] from 8.5 check-in: b6d467a174 user: sebres tags: core-8-6-branch
09:49
fixes [92564326a98b5510]: wrong x64-aligned handle from readdir64 by opendir/rewinddir/closedir, if ... check-in: 85bcf84100 user: sebres tags: core-8-5-branch
2018-05-07
07:43
Deduplicate code in INST_STR_CMP, StringCmpCmd, and StringEqualCmd. check-in: 1841bf54d1 user: pooryorick tags: core-8-6-branch
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to unix/tclUnixFCmd.c.

   371    371   	char srcPath[MAXPATHLEN], dstPath[MAXPATHLEN];
   372    372   	DIR *dirPtr;
   373    373   	Tcl_DirEntry *dirEntPtr;
   374    374   
   375    375   	if ((Realpath((char *) src, srcPath) != NULL)	/* INTL: Native. */
   376    376   		&& (Realpath((char *) dst, dstPath) != NULL) /* INTL: Native */
   377    377   		&& (strncmp(srcPath, dstPath, strlen(srcPath)) != 0)) {
   378         -	    dirPtr = opendir(dst);			/* INTL: Native. */
          378  +	    dirPtr = TclOSopendir(dst);			/* INTL: Native. */
   379    379   	    if (dirPtr != NULL) {
   380    380   		while (1) {
   381    381   		    dirEntPtr = TclOSreaddir(dirPtr);	/* INTL: Native. */
   382    382   		    if (dirEntPtr == NULL) {
   383    383   			break;
   384    384   		    }
   385    385   		    if ((strcmp(dirEntPtr->d_name, ".") != 0) &&
   386    386   			    (strcmp(dirEntPtr->d_name, "..") != 0)) {
   387    387   			errno = EEXIST;
   388         -			closedir(dirPtr);
          388  +			TclOSclosedir(dirPtr);
   389    389   			return TCL_ERROR;
   390    390   		    }
   391    391   		}
   392         -		closedir(dirPtr);
          392  +		TclOSclosedir(dirPtr);
   393    393   	    }
   394    394   	}
   395    395   	errno = EINVAL;
   396    396       }
   397    397   #endif	/* !NO_REALPATH */
   398    398   
   399    399       if (strcmp(src, "/") == 0) {
................................................................................
   986    986   	 * Process the regular file
   987    987   	 */
   988    988   
   989    989   	return traverseProc(sourcePtr, targetPtr, &statBuf, DOTREE_F,
   990    990   		errorPtr);
   991    991       }
   992    992   #ifndef HAVE_FTS
   993         -    dirPtr = opendir(source);				/* INTL: Native. */
          993  +    dirPtr = TclOSopendir(source);			/* INTL: Native. */
   994    994       if (dirPtr == NULL) {
   995    995   	/*
   996    996   	 * Can't read directory
   997    997   	 */
   998    998   
   999    999   	errfile = source;
  1000   1000   	goto end;
  1001   1001       }
  1002   1002       result = traverseProc(sourcePtr, targetPtr, &statBuf, DOTREE_PRED,
  1003   1003   	    errorPtr);
  1004   1004       if (result != TCL_OK) {
  1005         -	closedir(dirPtr);
         1005  +	TclOSclosedir(dirPtr);
  1006   1006   	return result;
  1007   1007       }
  1008   1008   
  1009   1009       TclDStringAppendLiteral(sourcePtr, "/");
  1010   1010       sourceLen = Tcl_DStringLength(sourcePtr);
  1011   1011   
  1012   1012       if (targetPtr != NULL) {
................................................................................
  1048   1048   	if (doRewind && (numProcessed > MAX_READDIR_UNLINK_THRESHOLD)) {
  1049   1049   	    /*
  1050   1050   	     * Call rewinddir if we've called unlink or rmdir so many times
  1051   1051   	     * (since the opendir or the previous rewinddir), to avoid a
  1052   1052   	     * NULL-return that may a symptom of a buggy readdir.
  1053   1053   	     */
  1054   1054   
  1055         -	    rewinddir(dirPtr);
         1055  +	    TclOSrewinddir(dirPtr);
  1056   1056   	    numProcessed = 0;
  1057   1057   	}
  1058   1058       }
  1059         -    closedir(dirPtr);
         1059  +    TclOSclosedir(dirPtr);
  1060   1060   
  1061   1061       /*
  1062   1062        * Strip off the trailing slash we added
  1063   1063        */
  1064   1064   
  1065   1065       Tcl_DStringSetLength(sourcePtr, sourceLen - 1);
  1066   1066       if (targetPtr != NULL) {

Changes to unix/tclUnixFile.c.

   305    305   		|| !S_ISDIR(statBuf.st_mode)) {
   306    306   	    Tcl_DStringFree(&dsOrig);
   307    307   	    Tcl_DStringFree(&ds);
   308    308   	    Tcl_DecrRefCount(fileNamePtr);
   309    309   	    return TCL_OK;
   310    310   	}
   311    311   
   312         -	d = opendir(native);				/* INTL: Native. */
          312  +	d = TclOSopendir(native);				/* INTL: Native. */
   313    313   	if (d == NULL) {
   314    314   	    Tcl_DStringFree(&ds);
   315    315   	    if (interp != NULL) {
   316    316   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
   317    317   			"couldn't read directory \"%s\": %s",
   318    318   			Tcl_DStringValue(&dsOrig), Tcl_PosixError(interp)));
   319    319   	    }
................................................................................
   383    383   	    }
   384    384   	    Tcl_DStringFree(&utfDs);
   385    385   	    if (matchResult < 0) {
   386    386   		break;
   387    387   	    }
   388    388   	}
   389    389   
   390         -	closedir(d);
          390  +	TclOSclosedir(d);
   391    391   	Tcl_DStringFree(&ds);
   392    392   	Tcl_DStringFree(&dsOrig);
   393    393   	Tcl_DecrRefCount(fileNamePtr);
   394    394       }
   395    395       if (matchResult < 0) {
   396    396   	return TCL_ERROR;
   397    397       }

Changes to unix/tclUnixPort.h.

    55     55    * Parameterize for 64-bit filesystem support.
    56     56    *---------------------------------------------------------------------------
    57     57    */
    58     58   
    59     59   #ifdef HAVE_STRUCT_DIRENT64
    60     60   typedef struct dirent64	Tcl_DirEntry;
    61     61   #   define TclOSreaddir		readdir64
           62  +#   define TclOSopendir		opendir64
           63  +#   define TclOSrewinddir	rewinddir64
           64  +#   define TclOSclosedir	closedir64
    62     65   #else
    63     66   typedef struct dirent	Tcl_DirEntry;
    64     67   #   define TclOSreaddir		readdir
           68  +#   define TclOSopendir		opendir
           69  +#   define TclOSrewinddir	rewinddir
           70  +#   define TclOSclosedir	closedir
    65     71   #endif
    66     72   
    67     73   #ifdef HAVE_TYPE_OFF64_T
    68     74   typedef off64_t		Tcl_SeekOffset;
    69     75   #   define TclOSseek		lseek64
    70     76   #   define TclOSopen		open64
    71     77   #else