Avoid signed integer overflow when convering linux timeval to timespec
Linux accepts garbage as timeout and attempts to set it to something meaningful. Instead of checking for valid ranges of usec, just convert the type safely, regardless of what is inside it.
This commit is contained in:
parent
a13c9853a0
commit
db47bebf8c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: linux_misc.c,v 1.244 2019/08/24 14:21:13 maxv Exp $ */
|
||||
/* $NetBSD: linux_misc.c,v 1.245 2019/09/20 15:25:19 kamil Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -57,7 +57,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.244 2019/08/24 14:21:13 maxv Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.245 2019/09/20 15:25:19 kamil Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -875,7 +875,7 @@ linux_select1(struct lwp *l, register_t *retval, int nfds, fd_set *readfds,
|
|||
if ((error = copyin(timeout, <v, sizeof(ltv))))
|
||||
return error;
|
||||
uts.tv_sec = ltv.tv_sec;
|
||||
uts.tv_nsec = ltv.tv_usec * 1000;
|
||||
uts.tv_nsec = (long)((unsigned long)ltv.tv_usec * 1000);
|
||||
if (itimespecfix(&uts)) {
|
||||
/*
|
||||
* The timeval was invalid. Convert it to something
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: linux32_unistd.c,v 1.40 2017/12/26 08:30:58 kamil Exp $ */
|
||||
/* $NetBSD: linux32_unistd.c,v 1.41 2019/09/20 15:25:19 kamil Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
|
||||
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.40 2017/12/26 08:30:58 kamil Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.41 2019/09/20 15:25:19 kamil Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
@ -165,7 +165,7 @@ linux32_select1(struct lwp *l, register_t *retval, int nfds,
|
|||
return error;
|
||||
|
||||
uts.tv_sec = utv32.tv_sec;
|
||||
uts.tv_nsec = utv32.tv_usec * 1000;
|
||||
uts.tv_nsec = (long)((unsigned long)utv32.tv_usec * 1000);
|
||||
|
||||
if (itimespecfix(&uts)) {
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue