svn commit: r316070 - stable/10/lib/libkvm
Ngie Cooper
ngie at FreeBSD.org
Tue Mar 28 05:57:21 UTC 2017
Author: ngie
Date: Tue Mar 28 05:57:20 2017
New Revision: 316070
URL: https://svnweb.freebsd.org/changeset/base/316070
Log:
MFC r315647:
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.
Modified:
stable/10/lib/libkvm/kvm.c
stable/10/lib/libkvm/kvm_open.3
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/lib/libkvm/kvm.c
==============================================================================
--- stable/10/lib/libkvm/kvm.c Tue Mar 28 04:48:55 2017 (r316069)
+++ stable/10/lib/libkvm/kvm.c Tue Mar 28 05:57:20 2017 (r316070)
@@ -262,6 +262,10 @@ kvm_close(kvm_t *kd)
{
int error = 0;
+ if (kd == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
if (kd->pmfd >= 0)
error |= close(kd->pmfd);
if (kd->vmfd >= 0)
Modified: stable/10/lib/libkvm/kvm_open.3
==============================================================================
--- stable/10/lib/libkvm/kvm_open.3 Tue Mar 28 04:48:55 2017 (r316069)
+++ stable/10/lib/libkvm/kvm_open.3 Tue Mar 28 05:57:20 2017 (r316070)
@@ -32,7 +32,7 @@
.\" @(#)kvm_open.3 8.3 (Berkeley) 4/19/94
.\" $FreeBSD$
.\"
-.Dd January 29, 2004
+.Dd March 20, 2017
.Dt KVM_OPEN 3
.Os
.Sh NAME
@@ -181,10 +181,29 @@ is returned, in which case
writes 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 ,
More information about the svn-src-stable-10
mailing list