From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.2 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by inbox.vuxu.org (OpenSMTPD) with SMTP id bee0fab3 for ; Sun, 1 Mar 2020 06:58:48 +0000 (UTC) Received: (qmail 3713 invoked by uid 550); 1 Mar 2020 06:58:45 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 3683 invoked from network); 1 Mar 2020 06:58:44 -0000 From: Liu Jie To: CC: , Date: Sun, 1 Mar 2020 14:57:30 +0800 Message-ID: <20200301065730.146013-1-liujie1@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.113.189.241] X-CFilter-Loop: Reflected Subject: [musl] [PATCH] musl: lutimes: Add checks for input parameters For the input parameter struct timeval tv, need to determine whether it is invalid inputs. Signed-off-by: Liu Jie --- 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 #include #include +#include +#include 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