From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] musl: lutimes: Add checks for input parameters
Date: Sun, 1 Mar 2020 15:39:21 -0500 [thread overview]
Message-ID: <20200301203921.GN11469@brightrain.aerifal.cx> (raw)
In-Reply-To: <b01082fe-e391-e80a-d31b-84651236b1e5@sholland.org>
On Sun, Mar 01, 2020 at 02:37:38PM -0600, Samuel Holland wrote:
> On 3/1/20 1:17 AM, Rich Felker wrote:
> > On Sun, Mar 01, 2020 at 02:57:30PM +0800, Liu Jie wrote:
> >> For the input parameter struct timeval tv, need to
> >> determine whether it is invalid inputs.
> >>
> >> Signed-off-by: Liu Jie <liujie1@huawei.com>
> >> ---
> >> src/legacy/lutimes.c | 19 ++++++++++++++-----
> >> 1 file changed, 14 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/src/legacy/lutimes.c b/src/legacy/lutimes.c
> >> index 2e5502d1..6e7e1be3 100644
> >> --- a/src/legacy/lutimes.c
> >> +++ b/src/legacy/lutimes.c
> >> @@ -2,13 +2,22 @@
> >> #include <sys/stat.h>
> >> #include <sys/time.h>
> >> #include <fcntl.h>
> >> +#include <stdio.h>
> >> +#include <errno.h>
> >>
> >> int lutimes(const char *filename, const struct timeval tv[2])
> >> {
> >> struct timespec times[2];
> >> - times[0].tv_sec = tv[0].tv_sec;
> >> - times[0].tv_nsec = tv[0].tv_usec * 1000;
> >> - times[1].tv_sec = tv[1].tv_sec;
> >> - times[1].tv_nsec = tv[1].tv_usec * 1000;
> >> - return utimensat(AT_FDCWD, filename, times, AT_SYMLINK_NOFOLLOW);
> >> + if (tv != NULL) {
> >> + if (tv[0].tv_sec < 0 || tv[0].tv_usec < 0 ||
> >> + tv[1].tv_sec < 0 || tv[1].tv_usec < 0) {
> >> + errno = EINVAL;
> >> + return -1;
> >> + }
> >> + times[0].tv_sec = tv[0].tv_sec;
> >> + times[0].tv_nsec = tv[0].tv_usec * 1000;
> >> + times[1].tv_sec = tv[1].tv_sec;
> >> + times[1].tv_nsec = tv[1].tv_usec * 1000;
> >> + }
> >> + return utimensat(AT_FDCWD, filename, tv ? times : NULL, AT_SYMLINK_NOFOLLOW);
> >> }
> >> --
> >> 2.17.1
> >
> > This patch causes uninitialized timespecs to be used if a null pointer
> > is passed, silently corrupting data. If there is any historical
> > documented precedent for this function accepting a null pointer and
> > doing something meaningful, then the patch needs to do whatever that
> > meaningful thing is rather than usign uninitialized data. If not, the
> > preferred behavior is the current behavior: to crash so that the usage
> > error is caught.
>
> How do you see that uninitialized timespecs are used? times is only passed to
> utimensat if tv is nonnull, and in that case times is initialized.
Oh, I misread it. In that case it seems like it might be correct
as-is.
Rich
next prev parent reply other threads:[~2020-03-01 20:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-01 6:57 Liu Jie
2020-03-01 7:17 ` Rich Felker
2020-03-01 20:37 ` Samuel Holland
2020-03-01 20:39 ` Rich Felker [this message]
2020-03-20 19:54 ` Rich Felker
2020-03-01 8:37 ` Markus Wichmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200301203921.GN11469@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).