PERFORCE change 110876 for review
Alexander Leidinger
netchild at FreeBSD.org
Sat Dec 2 06:51:27 PST 2006
http://perforce.freebsd.org/chv.cgi?CH=110876
Change 110876 by netchild at 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));
More information about the p4-projects
mailing list