Date: Sat, 2 Dec 2006 14:51:21 GMT From: Alexander Leidinger <netchild@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 110876 for review Message-ID: <200612021451.kB2EpL8O062251@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=110876 Change 110876 by netchild@netchild_magellan on 2006/12/02 14:51:17 - use MIN - don't rely on undocumented features of copyinstr(9) Suggested by: rwatson Affected files ... .. //depot/projects/linuxolator/src/sys/compat/linux/linux_misc.c#40 edit Differences ... ==== //depot/projects/linuxolator/src/sys/compat/linux/linux_misc.c#40 (text+ko) ==== @@ -1648,15 +1648,24 @@ * do this here in the copyin, so that we don't need to * check on copyout. */ - max_size = (sizeof(comm) <= sizeof(p->p_comm)) ? - sizeof(comm) : sizeof(p->p_comm); + 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 && error != ENAMETOOLONG) + 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); - comm[sizeof(comm) - 1] = '\0'; /* terminate if truncated */ PROC_LOCK(p); strlcpy(p->p_comm, comm, sizeof(p->p_comm));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612021451.kB2EpL8O062251>