From nobody Tue Sep 27 16:20:49 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4McPxY4Tqwz4V99n; Tue, 27 Sep 2022 16:20:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4McPxY40wzz3n4s; Tue, 27 Sep 2022 16:20:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664295649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NZ8mJQ1frZvkh5+Yimwu5tXGpTowBezw32dSyyOY+OQ=; b=tqlvr9ouoCz6mVEoSlV1j22nBzbtRf//JyiB+KTxo/wBoqgTdwa9TFluwkCK0yzvblU5u/ N70d+sGOd06dF+rFJuetzgM0Lvt6YEhoD9HWq58C2oc+YfuHho9Jv52wngSK0yqCLpI0PI KdwGysUVqANlpMd8J7f94c7Y2cmQFABDDEbKeOPtGc6sh8iu1dPqRUaBkcw4xQH7mQvwxf afsGqcc9ffhZeZEowjZX/9/By3cXaQAhT+RymabwTS9PRPoewvDggcOIEZt/7EbO4BpeCX BjFIePR6M3wismg9yHH9hNckJg/MUkl+1R8yMiG0Hm0R9tnkUEF5EKIZeCjgdQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4McPxY33PCz19vY; Tue, 27 Sep 2022 16:20:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28RGKnAA097991; Tue, 27 Sep 2022 16:20:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28RGKn75097990; Tue, 27 Sep 2022 16:20:49 GMT (envelope-from git) Date: Tue, 27 Sep 2022 16:20:49 GMT Message-Id: <202209271620.28RGKn75097990@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kirk McKusick Subject: git: 3c67983babbb - stable/13 - Handle NULL return from localtime(3) in ls(1) and find(1) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3c67983babbb2c51e29424165f87adc8c4bf7dda Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664295649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NZ8mJQ1frZvkh5+Yimwu5tXGpTowBezw32dSyyOY+OQ=; b=xrd8rLxXg16zFP8V2VmagDyeXtHIdkIVuLRIlZS02A5N3VjdcL8pzLH562nCylJDKkE0wH NEQFYS92vDjnWopiLKqqE/6LL/JikFmFYcSguzLIX73ujoykAzvvzY5vgTPnZhKkYi1Cc7 qJ8mNZ8SxdTbnwI8uz1DtCLI2AqPGMQNrSMkJoEl3FCoMHTAXPfizkF1rk1ecRDFF0aTRj yr8jvLkVb8UiNEPwsevD70qlTREPJUbhhk4MKS5g2rJe48EPaulEQjXt4rqt1oPD3puOjx 0QUR9e6RidUSKSnfKvbJET1I6yKrVpodR9ZhHvIGIeevyse9qeE2b2Kh3azCgg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664295649; a=rsa-sha256; cv=none; b=ijaRD45DS5/7o7quv7LiNMGhZREy+i3kI7uK/Wnxg3zPbwQevxtIwpTdg89Xm9LHPxIsBo 4UOzFhvcfhwUpnGX+a9DRAgmTsekl8sewt+YX/Zg1kJjH2nD2W0LlJyvyM78uGUBObpDf7 v0DNWUy2DzyCX3E1rFea9b9VUpx1DPAvJHv3kd7wE2Ja7hfJyz8NSxm1xbnKb0v7Huf4mU BDGIxmX9wyMxeAJiQhG2Zu/DcO698eVOMyXoxP6u8/rmwNr40yk1hez3vKvhrBE+A/8OOx SZQFpT27U8cfJyoyE3SDcuypfuBNYJp9ZYwqjLRV+UFZjk1ZnsGh0A0kj46LSA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=3c67983babbb2c51e29424165f87adc8c4bf7dda commit 3c67983babbb2c51e29424165f87adc8c4bf7dda Author: Kirk McKusick AuthorDate: 2022-09-09 21:29:53 +0000 Commit: Kirk McKusick CommitDate: 2022-09-27 16:20:29 +0000 Handle NULL return from localtime(3) in ls(1) and find(1) (cherry picked from commit 927f8d8bbbed70f6c88d05c19b5b366f8e7532c9) --- bin/ls/print.c | 11 ++++++----- usr.bin/find/ls.c | 6 +++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bin/ls/print.c b/bin/ls/print.c index bbe5c6f8a6f6..5e8a54ca0620 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -432,18 +432,17 @@ printdev(size_t width, dev_t dev) (void)printf("%#*jx ", (u_int)width, (uintmax_t)dev); } -static size_t +static void ls_strftime(char *str, size_t len, const char *fmt, const struct tm *tm) { char *posb, nfmt[BUFSIZ]; const char *format = fmt; - size_t ret; if ((posb = strstr(fmt, "%b")) != NULL) { if (month_max_size == 0) { compute_abbreviated_month_size(); } - if (month_max_size > 0) { + if (month_max_size > 0 && tm != NULL) { snprintf(nfmt, sizeof(nfmt), "%.*s%s%*s%s", (int)(posb - fmt), fmt, get_abmon(tm->tm_mon), @@ -453,8 +452,10 @@ ls_strftime(char *str, size_t len, const char *fmt, const struct tm *tm) format = nfmt; } } - ret = strftime(str, len, format, tm); - return (ret); + if (tm != NULL) + strftime(str, len, format, tm); + else + strlcpy(str, "bad date val", len); } static void diff --git a/usr.bin/find/ls.c b/usr.bin/find/ls.c index 8c4c16ed3461..8d7406216256 100644 --- a/usr.bin/find/ls.c +++ b/usr.bin/find/ls.c @@ -88,6 +88,7 @@ printtime(time_t ftime) static time_t lnow; const char *format; static int d_first = -1; + struct tm *tm; #ifdef D_MD_ORDER if (d_first < 0) @@ -103,7 +104,10 @@ printtime(time_t ftime) else /* mmm dd yyyy || dd mmm yyyy */ format = d_first ? "%e %b %Y " : "%b %e %Y "; - strftime(longstring, sizeof(longstring), format, localtime(&ftime)); + if ((tm = localtime(&ftime)) != NULL) + strftime(longstring, sizeof(longstring), format, tm); + else + strlcpy(longstring, "bad date val ", sizeof(longstring)); fputs(longstring, stdout); }