Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Reproducer on NetBSD i386: $ arch/netbsd.i386/bin/ksh -c 'TIMEFORMAT=%1U; time sleep 0' 0_0000000000000000000000000000000000000000000001 ...where the _ is actually a 0 byte. The format is similarly corrupted for other values of TIMEFORMAT. The cause is on xec.c line 299, where the sfprintf statement passes tvp->tv_sec to sfprintf with the %d modifier -- assuming it is a regular int type. tv_sec is of type time_t, but on NetBSD, time_t is defined as long, which on i386 is twice the size of an int. Hence the corrupted output of sfprintf. Arguments *must* match the type length of the formatters exactly. POSIX only says that time_t is "an integer type", so we cannot assume its size. It is thus unsafe to pass directly to *printf as there is always a chance the formatter will mismatch with the type. src/cmd/ksh93/sh/xec.c: - Assign tvp->tv_sec to a local variable of type 'long' (which does an implicit typecast if necessary) before passing it to sfprintf using the %ld formatter.
- Loading branch information