Author: andrew
Date: Wed Sep  9 11:51:14 2015
New Revision: 287596
URL: https://svnweb.freebsd.org/changeset/base/287596

Log:
  Rework copyinstr to:
   * Fail when the length passed in is 0
   * Remove an unneeded increment of the count on success
   * Return ENAMETOOLONG when the input pointer is too long
  
  Sponsored by: ABT Systems Ltd

Modified:
  head/sys/arm64/arm64/copyinout.S

Modified: head/sys/arm64/arm64/copyinout.S
==============================================================================
--- head/sys/arm64/arm64/copyinout.S    Wed Sep  9 09:19:07 2015        
(r287595)
+++ head/sys/arm64/arm64/copyinout.S    Wed Sep  9 11:51:14 2015        
(r287596)
@@ -95,6 +95,7 @@ END(copyin)
  */
 ENTRY(copyinstr)
        mov     x5, xzr         /* count = 0 */
+       mov     w4, #1          /* If zero return faulure */
        cbz     x2, 3f          /* If len == 0 then skip loop */
 
        adr     x6, copyio_fault /* Get the handler address */
@@ -102,17 +103,18 @@ ENTRY(copyinstr)
 
 1:     ldrb    w4, [x0], #1    /* Load from uaddr */
        strb    w4, [x1], #1    /* Store in kaddr */
-       cbz     w4, 2f          /* If == 0 then break */
-       sub     x2, x2, #1      /* len-- */
        add     x5, x5, #1      /* count++ */
+       cbz     w4, 2f          /* Break when NUL-terminated */
+       sub     x2, x2, #1      /* len-- */
        cbnz    x2, 1b
 
 2:     SET_FAULT_HANDLER(xzr, x7) /* Clear the handler */
 
 3:     cbz     x3, 4f          /* Check if done != NULL */
-       add     x5, x5, #1      /* count++ */
        str     x5, [x3]        /* done = count */
 
-4:     mov     x0, xzr         /* return 0 */
+4:     mov     w1, #ENAMETOOLONG /* Load ENAMETOOLONG to return if failed */
+       cmp     w4, #0          /* Check if we saved the NUL-terminator */
+       csel    w0, wzr, w1, eq /* If so return success, else failure */
        ret
 END(copyinstr)
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to