diff options
author | Enji Cooper <ngie@FreeBSD.org> | 2017-03-20 18:28:22 +0000 |
---|---|---|
committer | Enji Cooper <ngie@FreeBSD.org> | 2017-03-20 18:28:22 +0000 |
commit | 54fc00f7f9e268c525b62eed01b615acf92846a3 (patch) | |
tree | 797bf047813a4ec4a101106360be8b6a0e31bbd5 /lib/libkvm | |
parent | 11e46b7133c500292817826e2078a83253d01b5d (diff) | |
download | src-test-54fc00f7f9e268c525b62eed01b615acf92846a3.tar.gz src-test-54fc00f7f9e268c525b62eed01b615acf92846a3.zip |
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
Notes
Notes:
svn path=/head/; revision=315647
Diffstat (limited to 'lib/libkvm')
-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 2d67dbf5df274..d0dbded1c387a 100644 --- a/lib/libkvm/kvm.c +++ b/lib/libkvm/kvm.c @@ -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) diff --git a/lib/libkvm/kvm_open.3 b/lib/libkvm/kvm_open.3 index 43fae31a79491..f66e7af10efdc 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 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 , |