Does copyinstr guarantee that it has filled the output buffer when it
returns ENAMETOOLONG?  I usually try to answer my own questions, but I
don't speak many dialects of assembly.  :)

I ask because I'd like to make the following change, and I'd like to
know whether I should zero the buffer before calling copyinstr to ensure
that I don't set the thread's name to the garbage that was on the stack.

Eric

Index: kern_thr.c
===================================================================
--- kern_thr.c  (revision 308217)
+++ kern_thr.c  (working copy)
@@ -580,8 +580,13 @@ sys_thr_set_name(struct thread *td, struct thr_set
        if (uap->name != NULL) {
                error = copyinstr(uap->name, name, sizeof(name),
                        NULL);
-               if (error)
-                       return (error);
+               if (error) {
+                       if (error == ENAMETOOLONG) {
+                               name[sizeof(name) - 1] = '\0';
+                       } else {
+                               return (error);
+                       }
+               }
        }
        p = td->td_proc;
        ttd = tdfind((lwpid_t)uap->id, p->p_pid);
_______________________________________________
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Reply via email to