]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/arm/stubs.c
xnu-6153.11.26.tar.gz
[apple/xnu.git] / bsd / dev / arm / stubs.c
index 644dae6304fffed22726c90c650327612edfb898..a76f54b60e5dfe0fbb57ba65bfd3d1b915a85523 100644 (file)
@@ -7,6 +7,7 @@
  *
  */
 
+#include <sys/cdefs.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/ioctl.h>
@@ -33,15 +34,21 @@ copyoutstr(const void *from, user_addr_t to, size_t maxlen, size_t * lencopied)
 {
        size_t          slen;
        size_t          len;
-       int             error = 0;
+       int             error = copyoutstr_prevalidate(from, to, maxlen);
+
+       if (__improbable(error)) {
+               return error;
+       }
 
        slen = strlen(from) + 1;
-       if (slen > maxlen)
+       if (slen > maxlen) {
                error = ENAMETOOLONG;
+       }
 
        len = min(maxlen, slen);
-       if (copyout(from, to, len))
+       if (copyout(from, to, len)) {
                error = EFAULT;
+       }
        *lencopied = len;
 
        return error;
@@ -65,13 +72,15 @@ copystr(const void *vfrom, void *vto, size_t maxlen, size_t * lencopied)
 
        for (l = 0; l < maxlen; l++) {
                if ((*to++ = *from++) == '\0') {
-                       if (lencopied)
+                       if (lencopied) {
                                *lencopied = l + 1;
+                       }
                        return 0;
                }
        }
-       if (lencopied)
+       if (lencopied) {
                *lencopied = maxlen;
+       }
        return ENAMETOOLONG;
 }