freebsd-src/usr.bin
Kirk McKusick 927f8d8bbb Handle NULL return from localtime(3) in ls(1) and find(1)
The ls(1) (with -l option) and find(1) (with -ls option) utilties
segment fault when operating on files with very large modification
times. A recent disk corruption set a spurious bit in the mtime
field of one of my files to 0x8000000630b0167 (576460753965089127)
which is in year 18,266,940,962. I discovered the problem when
running fsck_ffs(8) which uses ctime(3) to convert it to a readable
format. Ctime cannot fit the year into its four character field, so
returns ??? ??? ?? ??:??:?? ???? (typically Thu Nov 24 18:22:48 2021).

With the filesystem mounted, I used `ls -l' to see how it would
report the modification time and it segment faulted. The find(1)
program also segment faulted (see script below). Both these utilities
call the localtime(3) function to decode the modification time.
Localtime(3) returns a pointer to a struct tm (which breaks things
out into its component pieces: year, month, day, hour, minute,
second). The ls(1) and find(1) utilities then print out the date
based on the appropriate fields in the returned tm structure.

Although not documented in the localtime(3) manual page, localtime(3)
returns a NULL pointer if the passed in time translates to a year
that will not fit in an "int" (which if "int" is 32-bits cannot
hold the year 18,266,940,962). Since ls(1) and find(1) do not check
for a NULL struct tm * return from localtime(3), they segment fault
when they try to dereference it.

When localtime(3) returns NULL, the attached patches produce a date
string of "bad date val". This string is chosen because it has the
same number of characters (12) and white spaces (2) as the usual
date string, for example "Sep 3 22:06" or "May 15 2017".

The most recent ANSI standard for localtime(3) does say that localtime(3)
can return NULL (see https://pubs.opengroup.org/onlinepubs/9699919799/
and enter localtime in the search box). Our localtime(3) man page should
be updated to indicate that NULL is a possible return. More importantly,
there are over 100 uses of localtime(3) in the FreeBSD source tree (see
Differential Revision D36474 for the list). Most do not check for a NULL
return from localtime(3).

Reported by:  Peter Holm
Reviewed by:  kib, Chuck Silvers, Warner Losh
MFC after:    2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36474
2022-09-09 14:30:42 -07:00
..
addr2line
alias
apply apply: clean up error handling. 2022-08-08 19:06:35 +00:00
ar ar: Avoid overwriting the stdout file stream pointer 2022-01-27 17:10:17 -05:00
asa
at at(1): Markup environment variables with proper macros 2020-07-19 14:42:13 +00:00
atm
awk awk: Move to using two sets of tests 2021-11-05 08:53:36 -06:00
backlight backlight(8): Update usage() to match the manual page 2022-07-19 16:56:27 +02:00
banner manpages: Fix use of At macro 2022-03-04 00:03:44 +01:00
basename manpages: Fix use of At macro 2022-03-04 00:03:44 +01:00
bc Sync with OpenBSD. 2019-01-12 12:35:02 +00:00
beep beep(1): Initial version of utility to create terminal beep via soundcard. 2021-11-04 09:00:46 +01:00
biff
bintrans bintrans: replace the quoted printable encoder/decoder 2022-08-25 09:29:18 +02:00
bluetooth pkgbase: Add a FreeBSD-bluetooth package 2019-07-19 15:10:03 +00:00
bmake Update to bmake-20220726 2022-07-27 09:00:30 -07:00
brandelf fix URL typo 2022-02-05 09:08:45 +00:00
bsdcat libarchive: import changes from upstream 2022-02-10 00:35:42 +01:00
bsddialog bsddialog(1): Fix Makefile typo 2022-09-03 17:46:26 +02:00
bsdiff bsdiff: fix off-by-one error 2020-11-16 18:41:49 +00:00
bzip2 Install all bzip2.1 MLINKs from the same place. 2019-08-28 21:01:51 +00:00
bzip2recover Install all bzip2.1 MLINKs from the same place. 2019-08-28 21:01:51 +00:00
c89
c99
caesar
calendar calendar: clarify comment syntax in man page 2022-07-31 07:37:05 +02:00
cap_mkdb
chat Fix a few mandoc issues 2020-10-09 14:03:45 +00:00
chkey Update Makefile.depend files 2019-12-11 17:37:53 +00:00
chpass usr.bin/chpass: Correct manpage regarding path to temp files 2021-05-25 16:23:20 +01:00
cksum usr.bin/cksum: localize _total variables. 2022-07-17 17:24:31 -07:00
clang Merge llvm-project main llvmorg-14-init-17616-g024a1fab5c35 2022-05-14 13:44:34 +02:00
cmp cmp: initialize limit to avoid stack garbage limits 2021-10-21 11:30:55 -05:00
col col(1): Add EXAMPLES section 2020-10-21 16:30:34 +00:00
colrm colrm.1: Add a missing colon 2020-06-23 10:27:41 +00:00
column
comm comm(1): Add EXAMPLES section 2020-07-27 16:51:23 +00:00
compile_et pkgbase: Create a FreeBSD-kerberos package 2021-09-07 10:23:14 +02:00
compress compress(1): warn about link handling 2021-03-04 14:52:12 +01:00
cpio libarchive: import changes from upstream 2022-02-10 00:35:42 +01:00
cpuset sys/bitset.h: reduce visibility of BIT_* macros 2021-12-05 23:00:25 +01:00
csplit
ctags
ctlstat ctlstat: add prometheus output 2022-04-20 15:18:41 -06:00
cut cut: Fix out of boundary write on illegal list argument 2018-05-23 09:16:20 +00:00
cxxfilt
dc Adjust history, info source from v1's manuals 2019-09-04 13:44:46 +00:00
diff diff: tests: loosen up requirements for report_identical 2022-04-18 23:04:13 -05:00
diff3 diff3: Use ranges for new and old diffedits in ed scripts 2022-08-02 14:38:11 +01:00
dirname Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0. 2018-06-19 23:43:14 +00:00
dpv Indicate the port where the referenced man pages come from. 2022-08-16 20:57:30 +02:00
drill Rename NO_WERROR -> MK_WERROR=no 2021-01-07 09:31:03 +00:00
dtc usr.bin/dtc: Include <limits> for std::numeric_limits<>. 2022-06-09 10:20:03 -07:00
du du_test: Skip three tests if sparse files are not supported 2021-02-03 17:06:07 +00:00
ee ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
elfctl elfctl: whitespace cleanup 2022-02-15 08:46:14 -05:00
elfdump elfdump: handle small files more gracefully 2022-02-17 10:09:53 -06:00
enigma Indicate which port gpg.1 comes from. 2022-08-17 19:23:57 +02:00
env pkgbase: Put more binaries/lib in runtime 2021-12-21 10:17:27 +01:00
etdump etdump: Fix the file name included in the could not open error message 2022-01-16 06:55:39 +00:00
expand [expand] add __dead2 annotation to usage 2018-05-11 06:55:02 +00:00
factor Fix the way 'factor' behaves when using OpenSSL to match the description 2020-01-12 20:25:11 +00:00
false
fetch fetch: make -S argument accept values > 2GB 2022-02-20 15:24:43 +01:00
file Integrate contrib/file/tests with kyua/atf 2022-02-16 13:02:45 -06:00
file2c
find Handle NULL return from localtime(3) in ls(1) and find(1) 2022-09-09 14:30:42 -07:00
finger
fmt Fix some common typos in comments 2021-03-13 18:26:15 +01:00
fold fold(1): Add EXAMPLES section 2020-10-29 18:39:04 +00:00
fortune mixer: remove volume backwards compat, add % interpretation 2022-06-17 22:50:58 -05:00
from
fstat fuser: restore functionality by fixing fsid type 2021-11-01 08:45:26 +02:00
fsync pkgbase: Put a lot of binaries and lib in FreeBSD-runtime 2019-09-05 14:13:08 +00:00
ftp pkgbase: Create a FreeBSD-ftp package 2021-09-07 10:25:23 +02:00
gcore Indicate which port gdb.1 and kgdb.1 come from. 2022-08-17 19:13:22 +02:00
gencat
getaddrinfo
getconf Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00
getent getent(1): Add EXAMPLES section 2020-10-24 16:40:34 +00:00
getopt Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0. 2018-06-19 23:43:14 +00:00
gh-bc usr.bin/bc: update to version 5.3.1 2022-06-11 13:14:37 +02:00
gprof gprof: Retire a.out support 2020-12-26 11:47:47 -05:00
grdc ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
grep pkgbase: Put more binaries/lib in runtime 2021-12-21 10:17:27 +01:00
gzip zdiff: avoid non-conformant features 2022-05-30 19:25:16 -05:00
head Improve usability of head(1) and tail(1): 2022-07-12 21:14:25 -07:00
hesinfo Bump .Dd for recently modified manual pages 2022-06-27 18:20:03 +02:00
hexdump hexdump: Flush stdout after '*' (repeat) lines. 2021-07-29 06:40:57 +00:00
host
iconv iconv: only conditionally use ICONV_SET_DISCARD_ILSEQ 2022-08-11 11:33:28 -05:00
id pkgbase: Put more binaries/lib in runtime 2021-12-21 10:17:27 +01:00
ident ident: replace sbuf(9) with open_memstream(3) 2021-10-28 15:51:23 +02:00
indent Fix a few typos in source code comments 2021-08-14 10:08:49 +02:00
ipcrm Fix build post r330299 2018-03-02 23:31:55 +00:00
ipcs ipcs(1): drop obsolete error checking 2019-02-07 14:29:45 +00:00
iscsictl iscsi: per-session timeouts and rapid teardown of session on reconnect 2022-02-25 10:35:47 +01:00
join join(1): Add EXAMPLES section 2020-06-20 11:27:59 +00:00
jot jot.1: Explain default argument values more precisely 2019-09-21 15:01:11 +00:00
kdump kdump(1): Sort options in alphabetical order. 2022-07-16 12:47:54 +03:00
keylogin
keylogout
killall killall(1): Clarify -d, -s and -v options 2020-06-27 11:28:11 +00:00
ktrace Make it clear what the userland traces are in the ktrace(1) man page. 2019-08-26 10:18:19 +00:00
ktrdump ktrdump: properly parse %% in the format string 2021-12-29 23:08:15 -08:00
kyua Simplify and speed up the kyua build 2021-07-02 09:21:05 +01:00
lam The lam(1) man page is unclear about the uppercase versions of the flags 2019-01-04 02:48:43 +00:00
last pkgbase: Put accounting utilities in the acct package 2022-08-16 21:15:19 +02:00
lastcomm lastcomm/sa: Remove sparc64 tests, they aren't needed. 2021-10-04 10:51:15 -06:00
ldd ldd: also use exec mode for -a 2021-11-15 22:49:33 +02:00
ldd32 libcompat: Correct rtld MLINKS 2019-11-12 22:31:59 +00:00
leave Add extremely useful calendar(1) application to FreeBSD 2020-03-03 00:20:08 +00:00
less MFV: less v608 2022-09-05 22:52:39 -07:00
lessecho
lesskey less: upgrade to v590. 2021-07-17 22:20:44 -07:00
lex usr.bin/lex: regenerate bootstrap files after d37f81e35b 2021-04-21 10:56:29 +01:00
limits pkgbase: Put more binaries/lib in runtime 2021-12-21 10:17:27 +01:00
locale locale: exit 1 if unknown keyword was specified 2020-06-13 08:37:24 +00:00
localedef localedef: Fix bootstrapping on Ubuntu 16.04 2021-02-10 16:41:35 +00:00
locate improve c style 2022-02-14 19:30:09 +00:00
lock lock(1): Add EXAMPLES section 2020-12-11 19:27:21 +00:00
lockf Remove whitespace which accidentaly snuck into r364831. 2020-08-26 19:28:30 +00:00
logger logger.1: Clarify -i flag 2022-03-16 11:41:55 +01:00
login Fix hand-rolled METALOG entries for installconfig during distributeworld 2022-02-28 22:36:39 +00:00
logins
logname Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0. 2018-06-19 23:43:14 +00:00
look look(1): Add EXAMPLES section 2020-12-29 21:48:12 +01:00
lorder lorder: add note that it is no longer required 2021-12-20 12:59:01 -05:00
lsvfs lsvfs: one last style nit missed in 946585179d 2022-02-10 16:14:17 -06:00
lzmainfo
m4 m4(1): Add a SEE ALSO section and reference an AT&T manual 2021-04-08 21:16:54 +02:00
mail Replace literal uses of /usr/local in C sources with _PATH_LOCALBASE 2020-10-27 11:29:11 +00:00
man Indicate that xrefs to *roff,tbl,eqn et al are found in ports/textproc/groff. 2022-08-15 22:15:18 +02:00
mandoc Remove quotes around Makefile .error/.warn/.info strings 2022-01-22 14:03:07 -05:00
mesg
ministat Add a -q flag to ministat to suppress headers in output, for use with -n. 2021-12-18 22:53:03 +00:00
mkcsmapper update external URL 2022-02-05 09:13:07 +00:00
mkcsmapper_static Remove mkcsmapper_static and mkesdb_static from build-tools 2021-08-02 14:33:25 +01:00
mkdep
mkesdb update external URL 2022-02-05 08:58:30 +00:00
mkesdb_static Remove mkcsmapper_static and mkesdb_static from build-tools 2021-08-02 14:33:25 +01:00
mkfifo
mkimg mkimg: zero entry in vhdx_write_metadata 2021-11-20 19:37:25 -05:00
mkstr
mktemp better unique file names 2022-02-12 11:35:51 +00:00
mkuzip geom_uzip(4), mkuzip(8): Add Zstd image mode 2019-08-13 23:32:56 +00:00
morse
msgs ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
mt Add the LTO-9 density code to libmt and the mt(1) man page. 2020-12-10 21:06:06 +00:00
nc Add -M option to nc(1), which makes it print the TCP connection 2019-12-14 10:53:52 +00:00
ncal ncal: LT is the country code for Lithuania 2022-07-28 11:35:50 -06:00
ncurses ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
netstat divert(4): provide statistics 2022-08-30 15:09:21 -07:00
newgrp
newkey newkey(8): fix 'tmpname' memory leak (always) and input file descriptor leak 2019-02-08 14:31:44 +00:00
nfsstat nfsstat: Add an entry to output NFSPROC_APPENDWRITE count 2022-05-28 16:27:02 -07:00
nice
nl nl: Correct history 2022-07-24 15:01:52 -06:00
nm Update Makefile.depend files 2019-12-11 17:37:53 +00:00
nohup Cross-reference nohup(1) and daemon(8). 2018-11-09 13:47:06 +00:00
number
objcopy remove doubled name in objcopy manpage 2018-09-11 20:32:57 +00:00
ofed irdma: Add RDMA driver for Intel(R) Ethernet Controller E810 2022-05-23 16:52:49 -07:00
opieinfo
opiekey
opiepasswd
pagesize
pamtest
passwd pkgbase: Put a lot of binaries and lib in FreeBSD-runtime 2019-09-05 14:13:08 +00:00
paste Fix confusing example in paste(1) 2021-05-31 16:12:44 -06:00
patch patch: cleanup variable initialization a bit. 2021-07-22 14:23:22 -05:00
pathchk
perror
pom pom: Fix fencepost bugs. 2018-11-20 00:06:53 +00:00
posixshmcontrol posixshm: Add a -j option to posixshmcontrol ls, to specify a jail 2022-02-26 17:45:28 -08:00
pr Drop "All rights reserved" from the files I own 2019-03-11 22:23:56 +00:00
primes Fix the way 'factor' behaves when using OpenSSL to match the description 2020-01-12 20:25:11 +00:00
printenv Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0. 2018-06-19 23:43:14 +00:00
printf printf(1): Add EXAMPLES section 2020-07-01 16:33:32 +00:00
proccontrol proccontrol(1): Add wxmap control 2021-09-17 15:42:07 +03:00
procstat procstat: fix printing divert(4) sockets 2022-08-30 16:26:21 -07:00
protect protect.1: Document that protect(1) does not work in jails 2022-07-12 00:47:58 +02:00
quota Fix some common typos in comments 2021-08-08 10:16:06 +02:00
random random(6): Re-add undocumented support for floating point denominators 2020-02-15 19:13:37 +00:00
rctl Drop "All rights reserved" from all my stuff. This includes 2020-10-28 13:46:11 +00:00
readelf readelf: Add -z decompression support 2020-10-31 15:27:45 +00:00
renice renice: add unit tests. 2022-08-25 20:06:20 +00:00
resizewin For man page references found in ports, indicate the respective port. 2022-08-14 15:02:06 +02:00
rev rev(1): Add EXAMPLES section 2020-06-27 11:19:18 +00:00
revoke
rpcgen rpcgen: make compiler arglist allocation dynamic 2019-10-15 16:05:17 +00:00
rpcinfo
rs
rup rup: Fix -Wcast-align warnings 2018-07-03 19:09:46 +00:00
ruptime Remove extra spaces for the load average of machines that are down. 2020-04-04 12:07:36 +00:00
rusers rusers: modernize a bit 2018-06-25 11:44:56 +00:00
rwall
rwho capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
script script: use %n at the end of default tstamp_fmt 2022-03-10 09:42:55 -08:00
sdiff
sdiotool
sed sed(1): Fix a typo in a source code comment 2022-06-04 20:27:45 +02:00
seq seq(1): complete EXAMPLES section 2020-06-20 11:24:29 +00:00
shar Shar files may be seen as binary by grep. 2019-01-31 23:21:18 +00:00
showmount [showmount] implement long options 2019-12-12 05:11:53 +00:00
size Update Makefile.depend files 2019-12-11 17:37:53 +00:00
smbutil
sockstat sockstat(1): print PID adjusted to the right 2022-07-06 22:19:08 -07:00
soelim Indicate that xrefs to *roff,tbl,eqn et al are found in ports/textproc/groff. 2022-08-15 22:15:18 +02:00
sort Move sort to runtime 2022-07-29 11:27:25 +01:00
split split(1): Add EXAMPLES section 2020-06-18 15:14:10 +00:00
ssh-copy-id my copyright: some minor adjustments 2018-05-19 20:35:15 +00:00
stat tests: readlink: fix atf_test_case call [NFC] 2022-03-03 21:51:40 -06:00
stdbuf
strings Update Makefile.depend files 2019-12-11 17:37:53 +00:00
su Do not use macros in -width 2020-03-26 17:58:52 +00:00
systat systat.1: Fix lists 2022-04-02 00:49:53 +02:00
tabs ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
tail tail: Initialize the stat buffer used when input is stdin 2022-09-08 16:21:39 -04:00
talk ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
tar libarchive: import changes from upstream 2022-02-10 00:35:42 +01:00
tcopy
tee tee: use queue(9) in place of a custom linked list 2021-09-15 11:04:24 +00:00
telnet ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
tests
tftp update external URL 2022-02-05 09:00:35 +00:00
time time(1): Add EXAMPLES section 2020-07-07 16:07:39 +00:00
timeout timeout.1: Fix typos in examples 2021-10-21 13:07:32 +02:00
tip tip(1): Fix a typo in a source code comment 2022-09-03 14:59:03 +02:00
top top(1): Fix a typo in a source code comment 2022-04-02 14:53:20 +02:00
touch touch: don't leak descriptor if fstat(2) fails 2022-03-12 11:38:12 +01:00
tr Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0. 2018-06-19 23:43:14 +00:00
true
truncate truncate(1): Update tests' golden output 2021-08-21 17:04:21 +08:00
truss kdump: Decode getitimer, setitimer which argument 2022-06-22 14:19:31 +03:00
tsort tsort(1): Add EXAMPLES section 2020-08-30 17:37:56 +00:00
tty
ul ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
uname uname: -v: strip final whitespace compatibly with uname(3) 2022-02-18 16:30:10 +00:00
unexpand
unifdef unifdef.1: Fix typo on "input" 2021-10-05 20:27:16 -04:00
uniq Add EXAMPLES to cover all flags except -f since it is analogous to -s. 2020-06-07 13:21:47 +00:00
units Tell the world how to convert gigabytes to bytes with units(1) easily 2020-03-17 10:02:59 +00:00
unvis
unzip unzip: Fix segmentation fault if a zip file contains buggy filename. 2021-10-10 20:49:19 +09:00
usbhidaction mixer: remove volume backwards compat, add % interpretation 2022-06-17 22:50:58 -05:00
usbhidctl Include item position in report descriptor dump in usbhidctl(1). 2019-08-17 08:29:22 +00:00
users pkgbase: Put accounting utilities in the acct package 2022-08-16 21:15:19 +02:00
vacation
vgrind Indicate that xrefs to *roff,tbl,eqn et al are found in ports/textproc/groff. 2022-08-15 22:15:18 +02:00
vi ncurses: chase dependency changes in the source tree 2021-10-04 11:38:24 +02:00
vis
vmstat vmstat: correct history 2021-06-21 08:40:54 -06:00
vtfontcvt vtfontcvt: improve hex font format validation 2022-07-19 11:48:09 -04:00
w w(1): Add EXAMPLES to man page 2020-08-24 17:57:08 +00:00
wall Add RFC 5424 syslog message output to syslogd. 2018-04-15 08:34:16 +00:00
wc wc(1): document SIGINFO handling in the manual page. 2020-04-11 08:16:35 +00:00
what pkgbase: Put a lot of binaries and lib in FreeBSD-runtime 2019-09-05 14:13:08 +00:00
whereis whereis: fix fetching of user.cs_path sysctl variable 2022-02-04 23:44:34 +01:00
which Fix typo and environment variable macro 2020-09-24 16:42:17 +00:00
who pkgbase: Put accounting utilities in the acct package 2022-08-16 21:15:19 +02:00
whois whois: Handle referrals to rwhois servers. 2020-07-09 17:27:14 +00:00
write Remove extraneous setutxent() calls in write(1). 2019-01-23 20:02:17 +00:00
xargs xargs: fix description of strnsubst return value 2022-07-05 16:27:15 +01:00
xinstall xinstall: alphabetize: upper case precedes lower. 2022-08-04 02:10:16 +02:00
xo Allow proper builds of libxo's CSV encoder: 2019-12-16 22:05:03 +00:00
xohtml Import libxo-1.4.0: 2020-01-25 21:16:45 +00:00
xolint
xopo
xstr
xz
xzdec
yacc MFV: r362513 2020-07-14 01:54:24 +00:00
yes Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0. 2018-06-19 23:43:14 +00:00
ypcat pkgbase: Put yellow pages programs to its own package 2021-12-21 10:17:22 +01:00
ypmatch pkgbase: Put yellow pages programs to its own package 2021-12-21 10:17:22 +01:00
ypwhich pkgbase: Put yellow pages programs to its own package 2021-12-21 10:17:22 +01:00
zstd zstd: build with C11 2022-03-01 20:07:44 +00:00
Makefile Remove minigzip from the base system. 2022-08-13 21:11:50 -07:00
Makefile.amd64
Makefile.arm
Makefile.i386
Makefile.inc build: provide a default WARNS for all in-tree builds 2020-09-18 17:17:46 +00:00
Makefile.powerpc