From owner-freebsd-current@freebsd.org Wed Nov 2 19:24:47 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 315D2C2C997 for ; Wed, 2 Nov 2016 19:24:47 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from mailman.ysv.freebsd.org (unknown [127.0.1.3]) by mx1.freebsd.org (Postfix) with ESMTP id A62B01063 for ; Wed, 2 Nov 2016 19:24:46 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: by mailman.ysv.freebsd.org (Postfix) id A120DC2C996; Wed, 2 Nov 2016 19:24:46 +0000 (UTC) Delivered-To: current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A0A8FC2C995 for ; Wed, 2 Nov 2016 19:24:46 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from smtp.vangyzen.net (hotblack.vangyzen.net [IPv6:2607:fc50:1000:7400:216:3eff:fe72:314f]) by mx1.freebsd.org (Postfix) with ESMTP id 71C0C105E for ; Wed, 2 Nov 2016 19:24:46 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from sweettea.beer.town (unknown [76.164.8.130]) by smtp.vangyzen.net (Postfix) with ESMTPSA id BD4DE5648E for ; Wed, 2 Nov 2016 14:24:45 -0500 (CDT) To: "current@freebsd.org" From: Eric van Gyzen Subject: copyinstr and ENAMETOOLONG Message-ID: <236b8c7c-a12e-0872-f3cb-03f99bb5fcc5@FreeBSD.org> Date: Wed, 2 Nov 2016 14:24:43 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Nov 2016 19:24:47 -0000 Does copyinstr guarantee that it has filled the output buffer when it returns ENAMETOOLONG? I usually try to answer my own questions, but I don't speak many dialects of assembly. :) I ask because I'd like to make the following change, and I'd like to know whether I should zero the buffer before calling copyinstr to ensure that I don't set the thread's name to the garbage that was on the stack. Eric Index: kern_thr.c =================================================================== --- kern_thr.c (revision 308217) +++ kern_thr.c (working copy) @@ -580,8 +580,13 @@ sys_thr_set_name(struct thread *td, struct thr_set if (uap->name != NULL) { error = copyinstr(uap->name, name, sizeof(name), NULL); - if (error) - return (error); + if (error) { + if (error == ENAMETOOLONG) { + name[sizeof(name) - 1] = '\0'; + } else { + return (error); + } + } } p = td->td_proc; ttd = tdfind((lwpid_t)uap->id, p->p_pid);