From owner-p4-projects@FreeBSD.ORG Sat Dec 2 14:51:27 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D9BAA16A505; Sat, 2 Dec 2006 14:51:26 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A14FB16A500 for ; Sat, 2 Dec 2006 14:51:26 +0000 (UTC) (envelope-from netchild@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3ACBB43CAD for ; Sat, 2 Dec 2006 14:51:01 +0000 (GMT) (envelope-from netchild@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id kB2EpLOK062257 for ; Sat, 2 Dec 2006 14:51:21 GMT (envelope-from netchild@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kB2EpL8O062251 for perforce@freebsd.org; Sat, 2 Dec 2006 14:51:21 GMT (envelope-from netchild@freebsd.org) Date: Sat, 2 Dec 2006 14:51:21 GMT Message-Id: <200612021451.kB2EpL8O062251@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to netchild@freebsd.org using -f From: Alexander Leidinger To: Perforce Change Reviews Cc: Subject: PERFORCE change 110876 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Dec 2006 14:51:27 -0000 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));