Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2020-08-21
12:31 • Closed ticket [43b434812a]: Tcl 9.0 uses stat64() but not struct stat64 on Linux... artifact: 0a83b0484e user: jan.nijtmans
12:28
Fix [43b434812a]: Tcl 9.0 uses stat64() but not struct stat64 on Linux i686 check-in: 2864c3682e user: jan.nijtmans tags: trunk
10:05 • Ticket [43b434812a] Tcl 9.0 uses stat64() but not struct stat64 on Linux i686</i... artifact: d87fc87666 user: jan.nijtmans
09:28 • New ticket [43b434812a]. artifact: 6089758f12 user: chrstphrchvz

Tcl 9.0 uses stat64() but not struct stat64 on Linux i686

Closed / Fixed43b434812a6e79e3c5a2e394d57fda75a47af2b6Created 6 years agoUpdated 6 years ago
Descriptionwiki2020-08-21 09:28:27
Using Ubuntu 18.04 i686 (32 bit Intel), Tcl 9.0 ([c1e3046f2f]) appears to configure with TclOSstat() defined as stat64(), but also with Tcl_StatBuf defined to struct stat rather than struct stat64. Since struct stat64 is larger (96 bytes rather than 88), calling stat64() with a pointer to struct stat will write to memory outside of the struct stat. (The struct stat is likely also invalid after doing so.)

I notice this because I can't even start tclsh9.0 without it crashing in TclpMatchInDirectory() (tclUnixFile.c): calling TclOSstat() (stat64()) at line 312 clobbers the address stored in ds.string, and when Tcl_DStringSetLength() is called at line 380, it writes to an invalid address when doing dsPtr->string[length] = 0 (tclUtil.c line 2808).

I don't observe this issue in Tcl 8.7 ([95051c8d1e]) where TclOSstat() and Tcl_StatBuf are defined as stat64() and struct stat64 respectively.

Referenced by1
  • 2864c3682eFix [43b434812a]: Tcl 9.0 uses stat64() but not struct stat64 on Linux i686 check-in2020-08-21 12:28:26
jan.nijtmanswiki2020-08-21 10:05:55

See also the comments in this ticket: https://core.tcl-lang.org/tcl/info/02b58d5d04

Tcl 9.0 should use "Implicit LFS", while Tcl 8.x uses "Explicit LFS". What's missing is the "configure" part of determining `$(getconf LFS_CFLAGS)`, `$(getconf LFS_LDFLAGS)` and `$(getconf LFS_LIBS)`.

Thanks for reminding me, I know for UNIX this is not complete yet (for MacOS and Windows it is done already)

jan.nijtmanswiki2020-08-21 12:31:23

Well, until the implementation of [02b58d5d04] is complete, Tcl 9 should continue to use "struct stat64" on 32-bit platforms. Should be fixed now.

Thanks!

Log in (anonymous is fine) to add a comment.