From 78ee8c697e423a5b4718fabb53eef1c5f6a2a2b1 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 8 May 2018 09:49:16 +0000 Subject: fixes [92564326a98b5510]: wrong x64-aligned handle from readdir64 by opendir/rewinddir/closedir, if HAVE_STRUCT_DIRENT64 used. --- unix/tclUnixFCmd.c | 14 +++++++------- unix/tclUnixFile.c | 4 ++-- unix/tclUnixPort.h | 6 ++++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c index b5450b1..4377b77 100644 --- a/unix/tclUnixFCmd.c +++ b/unix/tclUnixFCmd.c @@ -333,7 +333,7 @@ DoRenameFile( if ((Realpath((char *) src, srcPath) != NULL) /* INTL: Native. */ && (Realpath((char *) dst, dstPath) != NULL) /* INTL: Native */ && (strncmp(srcPath, dstPath, strlen(srcPath)) != 0)) { - dirPtr = opendir(dst); /* INTL: Native. */ + dirPtr = TclOSopendir(dst); /* INTL: Native. */ if (dirPtr != NULL) { while (1) { dirEntPtr = TclOSreaddir(dirPtr); /* INTL: Native. */ @@ -343,11 +343,11 @@ DoRenameFile( if ((strcmp(dirEntPtr->d_name, ".") != 0) && (strcmp(dirEntPtr->d_name, "..") != 0)) { errno = EEXIST; - closedir(dirPtr); + TclOSclosedir(dirPtr); return TCL_ERROR; } } - closedir(dirPtr); + TclOSclosedir(dirPtr); } } errno = EINVAL; @@ -945,7 +945,7 @@ TraverseUnixTree( errorPtr); } #ifndef HAVE_FTS - dirPtr = opendir(source); /* INTL: Native. */ + dirPtr = TclOSopendir(source); /* INTL: Native. */ if (dirPtr == NULL) { /* * Can't read directory @@ -957,7 +957,7 @@ TraverseUnixTree( result = (*traverseProc)(sourcePtr, targetPtr, &statBuf, DOTREE_PRED, errorPtr); if (result != TCL_OK) { - closedir(dirPtr); + TclOSclosedir(dirPtr); return result; } @@ -1007,11 +1007,11 @@ TraverseUnixTree( * NULL-return that may a symptom of a buggy readdir. */ - rewinddir(dirPtr); + TclOSrewinddir(dirPtr); numProcessed = 0; } } - closedir(dirPtr); + TclOSclosedir(dirPtr); /* * Strip off the trailing slash we added diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index 0a2099c..1dc73ae 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -310,7 +310,7 @@ TclpMatchInDirectory( return TCL_OK; } - d = opendir(native); /* INTL: Native. */ + d = TclOSopendir(native); /* INTL: Native. */ if (d == NULL) { Tcl_DStringFree(&ds); if (interp != NULL) { @@ -383,7 +383,7 @@ TclpMatchInDirectory( } } - closedir(d); + TclOSclosedir(d); Tcl_DStringFree(&ds); Tcl_DStringFree(&dsOrig); Tcl_DecrRefCount(fileNamePtr); diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h index 965014e..cc31bf9 100644 --- a/unix/tclUnixPort.h +++ b/unix/tclUnixPort.h @@ -60,9 +60,15 @@ #ifdef HAVE_STRUCT_DIRENT64 typedef struct dirent64 Tcl_DirEntry; # define TclOSreaddir readdir64 +# define TclOSopendir opendir64 +# define TclOSrewinddir rewinddir64 +# define TclOSclosedir closedir64 #else typedef struct dirent Tcl_DirEntry; # define TclOSreaddir readdir +# define TclOSopendir opendir +# define TclOSrewinddir rewinddir +# define TclOSclosedir closedir #endif #ifdef HAVE_TYPE_OFF64_T -- cgit v0.12 From 47e9dbdc37939a6e874afd15d6586864649f23c7 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 8 May 2018 10:16:26 +0000 Subject: prevents UB/segfault by unexpected return-code (not -1/0/1) and avoid warnings like: tclCmdMZ.c:2815:15: warning: `s1` may be used uninitialized in this function [-Wmaybe-uninitialized] s1len = Tcl_NumUtfChars(s1, s1len); ^~~~~~~~~~~~~~~~~~~~~~~~~~ --- generic/tclCmdMZ.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index bc798b7..8530719 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -2772,6 +2772,7 @@ int TclStringCmp ( match = -1; goto matchdone; case 1: + default: /* avoid warn: `s2` may be used uninitialized */ match = 0; goto matchdone; } @@ -2786,6 +2787,7 @@ int TclStringCmp ( match = 1; goto matchdone; case 1: + default: /* avoid warn: `s1` may be used uninitialized */ match = 0; goto matchdone; } -- cgit v0.12