diff options
author | ngie <ngie@FreeBSD.org> | 2017-03-28 05:57:20 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2017-03-28 05:57:20 +0000 |
commit | 8832cc10cf95a896d6fb7d0054fbb5f6f0d154cd (patch) | |
tree | 4879c45fc324f2d6980988df8f14c9527bd209ea /lib | |
parent | 77b785069d6eae320236013da6d95b7f5b1bed39 (diff) | |
download | FreeBSD-src-8832cc10cf95a896d6fb7d0054fbb5f6f0d154cd.zip FreeBSD-src-8832cc10cf95a896d6fb7d0054fbb5f6f0d154cd.tar.gz |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libkvm/kvm.c | 4 | ||||
-rw-r--r-- | lib/libkvm/kvm_open.3 | 23 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c index d5a33aa..b814e8c 100644 --- a/lib/libkvm/kvm.c +++ b/lib/libkvm/kvm.c @@ -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) diff --git a/lib/libkvm/kvm_open.3 b/lib/libkvm/kvm_open.3 index 1b62482..62b9df2 100644 --- a/lib/libkvm/kvm_open.3 +++ b/lib/libkvm/kvm_open.3 @@ -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 , |