]> granicus.if.org Git - strace/commitdiff
Fix stat64 st_[acm]time decoding for personalities with 32-bit time_t
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 12 Mar 2015 16:59:01 +0000 (16:59 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 16 Mar 2015 14:23:09 +0000 (14:23 +0000)
STRUCT_STAT.st_[acm]time are declared as unsigned int for some
personalities, while time_t is signed.

* printstat.h (DO_PRINTSTAT): If st_[acm]time have the same size as int,
explicitly cast them to int.
* tests/stat64-v.test: Test that negative time_t is decoded properly.

Reported-by: Andreas Schwab <schwab@suse.de>
printstat.h
tests/stat64-v.test

index dd0b02e020d31d0cf7ed2c6ccd0fd77082d0b062..53112feac0ea52fefebbed3c09ab8e27ba653a7c 100644 (file)
@@ -57,9 +57,17 @@ DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf)
        }
 
        if (!abbrev(tcp)) {
-               tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
-               tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
-               tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
+               const bool cast = sizeof(statbuf->st_atime) == sizeof(int);
+
+               tprintf("st_atime=%s, ",
+                       sprinttime(cast ? (time_t) (int) statbuf->st_atime:
+                                         (time_t) statbuf->st_atime));
+               tprintf("st_mtime=%s, ",
+                       sprinttime(cast ? (time_t) (int) statbuf->st_mtime:
+                                         (time_t) statbuf->st_mtime));
+               tprintf("st_ctime=%s",
+                       sprinttime(cast ? (time_t) (int) statbuf->st_ctime:
+                                         (time_t) statbuf->st_ctime));
 #if HAVE_STRUCT_STAT_ST_FLAGS
                tprintf(", st_flags=%u", (unsigned int) statbuf->st_flags);
 #endif
index 49153861a16936041117113fed3bea525c99d879..f03254a92a33885039a7024091e6a8247f98d8ad 100755 (executable)
@@ -22,8 +22,7 @@ $truncate_cmd > "$OUT" 2>&1 || {
 ./stat $sample > /dev/null ||
        fail_ 'stat failed'
 
-touch -d '1970-01-01 36028797018963968 seconds' $sample ||
-touch -t 0102030405 $sample
+touch -d '1970-01-01 -42 seconds' $sample
 
 for f in $sample . /dev/null; do
        args="-v -efile ./stat $f"