From owner-svn-src-head@freebsd.org Mon Mar 20 18:28:24 2017 Return-Path: Delivered-To: svn-src-head@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 01B46D14DCA; Mon, 20 Mar 2017 18:28:24 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C2B0B13D2; Mon, 20 Mar 2017 18:28:23 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2KISMG5056258; Mon, 20 Mar 2017 18:28:22 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2KISMMt056256; Mon, 20 Mar 2017 18:28:22 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201703201828.v2KISMMt056256@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Mon, 20 Mar 2017 18:28:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315647 - head/lib/libkvm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Mar 2017 18:28:24 -0000 Author: ngie Date: Mon Mar 20 18:28:22 2017 New Revision: 315647 URL: https://svnweb.freebsd.org/changeset/base/315647 Log: Handle kd == NULL gracefully with kvm_close(3) Don't segfault in kvm_close(3) if provided a NULL pointer. Instead, return -1 and set errno to EINVAL. Document this new behavior explicitly. MFC after: 1 week Reviewed by: vangyzen Sponsored by: Dell EMC Isilon Differential Revision: D10065 Modified: head/lib/libkvm/kvm.c head/lib/libkvm/kvm_open.3 Modified: head/lib/libkvm/kvm.c ============================================================================== --- head/lib/libkvm/kvm.c Mon Mar 20 18:15:36 2017 (r315646) +++ head/lib/libkvm/kvm.c Mon Mar 20 18:28:22 2017 (r315647) @@ -272,6 +272,10 @@ kvm_close(kvm_t *kd) { int error = 0; + if (kd == NULL) { + errno = EINVAL; + return (-1); + } if (kd->vmst != NULL) kd->arch->ka_freevtop(kd); if (kd->pmfd >= 0) Modified: head/lib/libkvm/kvm_open.3 ============================================================================== --- head/lib/libkvm/kvm_open.3 Mon Mar 20 18:15:36 2017 (r315646) +++ head/lib/libkvm/kvm_open.3 Mon Mar 20 18:28:22 2017 (r315647) @@ -32,7 +32,7 @@ .\" @(#)kvm_open.3 8.3 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd March 19, 2017 +.Dd March 20, 2017 .Dt KVM_OPEN 3 .Os .Sh NAME @@ -227,10 +227,29 @@ and write the error message into .Fa errbuf . .Pp +.Rv -std kvm_close +.Sh ERRORS The .Fn kvm_close -function returns 0 on success and -1 on failure. +function may fail and set the global variable +.Va errno +for any of the errors specified for +.Xr close 2 . +.Pp +The +.Fn kvm_close +function may also fail and set +.Va errno +if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value passed via +.Fa kd +was +.Dv NULL . +.El .Sh SEE ALSO +.Xr close 2 , .Xr open 2 , .Xr kvm 3 , .Xr kvm_getargv 3 ,