Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/usermode/usermode Fix copystring routines to NOT ju...
details: https://anonhg.NetBSD.org/src/rev/1dd5b50ca6ad
branches: trunk
changeset: 768811:1dd5b50ca6ad
user: reinoud <reinoud%NetBSD.org@localhost>
date: Sat Aug 27 17:57:14 2011 +0000
description:
Fix copystring routines to NOT just copy all since not all space might be
writable. This can be fixed by implementing/importing strnlen(3) in the kernel
and/or for NetBSD/usermode to have onfaults in the copyins/copyouts.
diffstat:
sys/arch/usermode/usermode/copy.c | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
diffs (61 lines):
diff -r a94fb8ede4fe -r 1dd5b50ca6ad sys/arch/usermode/usermode/copy.c
--- a/sys/arch/usermode/usermode/copy.c Sat Aug 27 17:53:21 2011 +0000
+++ b/sys/arch/usermode/usermode/copy.c Sat Aug 27 17:57:14 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: copy.c,v 1.4 2011/08/25 19:07:45 reinoud Exp $ */
+/* $NetBSD: copy.c,v 1.5 2011/08/27 17:57:14 reinoud Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,13 +27,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copy.c,v 1.4 2011/08/25 19:07:45 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copy.c,v 1.5 2011/08/27 17:57:14 reinoud Exp $");
#include <sys/types.h>
#include <sys/systm.h>
-#include <sys/param.h> // tmp
-#include <uvm/uvm.h> // tmp
-#include <uvm/uvm_pmap.h> // tmp
+
+/* XXX until strnlen(3) has been added to the kernel, we *could* panic on it */
+#define strnlen(str, maxlen) min(strlen((str)), maxlen)
int
copyin(const void *uaddr, void *kaddr, size_t len)
@@ -54,27 +54,30 @@
int
copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done)
{
+ len = min(strnlen(uaddr, len), len) + 1;
strncpy(kaddr, uaddr, len);
if (done)
- *done = min(strlen(uaddr), len);
+ *done = len;
return 0;
}
int
copyoutstr(const void *kaddr, void *uaddr, size_t len, size_t *done)
{
+ len = min(strnlen(kaddr, len), len) + 1;
strncpy(uaddr, kaddr, len);
if (done)
- *done = min(strlen(kaddr), len);
+ *done = len;
return 0;
}
int
copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done)
{
+ len = min(strnlen(kfaddr, len), len) + 1;
strncpy(kdaddr, kfaddr, len);
if (done)
- *done = min(strlen(kfaddr), len);
+ *done = len;
return 0;
}
Home |
Main Index |
Thread Index |
Old Index