Module Name:    src
Committed By:   reinoud
Date:           Sat Aug 27 17:57:14 UTC 2011

Modified Files:
        src/sys/arch/usermode/usermode: copy.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/usermode/usermode/copy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/usermode/usermode/copy.c
diff -u src/sys/arch/usermode/usermode/copy.c:1.4 src/sys/arch/usermode/usermode/copy.c:1.5
--- src/sys/arch/usermode/usermode/copy.c:1.4	Thu Aug 25 19:07:45 2011
+++ src/sys/arch/usermode/usermode/copy.c	Sat Aug 27 17:57:14 2011
@@ -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 <jmcne...@invisible.ca>
@@ -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;
 }
 

Reply via email to