Changing copyinstr(9) invariants
    Alexander Leidinger 
    Alexander at Leidinger.net
       
    Sat Dec  2 08:24:37 PST 2006
    
    
  
Hi,
the copyinstr(9) documentation does not guarantee that in the
ENAMETOOLONG case the result is a completely filled up memory region
which contains a truncated string without termination.
The powerpc version works like this. And while I don't understand i386
ASM, it looks to me the i386 version does the same.
My questions:
 - Does the amd64/sparc64/ia64/... version do the same?
 - Are there reasons not to document this fact and then make use of
   it?
My motivation is in the linux_prctl() function in
src/sys/compat/linux/linux_misc.c:
---snip---
        case LINUX_PR_SET_NAME:
                max_size = MIN(sizeof(comm), sizeof(p->p_comm));
                error = copyinstr((void *)(register_t) args->arg2, comm,
                    max_size, NULL);
                /* Linux silently truncates the name if it is too long.
                if (error == ENAMETOOLONG) {
                        /*
                         * XXX: copyinstr() isn't documented to populate the
                         * array completely, so do a copyin() to be on the
                         * safe side. This should be changed in case
                         * copyinstr() is changed to guarantee this.
                         */
                        error = copyin((void *)(register_t)args->arg2, comm,
                            max_size - 1);
                        comm[max_size - 1] = '\0';
                }
                if (error)
                        return (error);
---snip---
By documenting this behavior I could get rid of the copyin() and just
terminate the string.
Bye,
Alexander.
-- 
'I'll tell you this!' shouted Rincewind. 'I'd rather trust me than history! Oh, shit, did I just say that?'
(Interesting Times)
http://www.Leidinger.net  Alexander @ Leidinger.net: PGP ID = B0063FE7
http://www.FreeBSD.org     netchild @ FreeBSD.org  : PGP ID = 72077137
    
    
More information about the freebsd-arch
mailing list