mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] musl: lutimes: Add checks for input parameters
@ 2020-03-01  6:57 Liu Jie
  2020-03-01  7:17 ` Rich Felker
  2020-03-01  8:37 ` Markus Wichmann
  0 siblings, 2 replies; 6+ messages in thread
From: Liu Jie @ 2020-03-01  6:57 UTC (permalink / raw)
  To: musl; +Cc: yunlong.song, liujie1

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-20 19:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-01  6:57 [musl] [PATCH] musl: lutimes: Add checks for input parameters Liu Jie
2020-03-01  7:17 ` Rich Felker
2020-03-01 20:37   ` Samuel Holland
2020-03-01 20:39     ` Rich Felker
2020-03-20 19:54       ` Rich Felker
2020-03-01  8:37 ` Markus Wichmann

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).