Date: Sat, 2 Dec 2006 17:25:00 +0100 From: Alexander Leidinger <Alexander@Leidinger.net> To: arch@freebsd.org Subject: Changing copyinstr(9) invariants Message-ID: <20061202172500.62b03d9c@Magellan.Leidinger.net>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20061202172500.62b03d9c>