summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-03-28 06:03:43 +0000
committerngie <ngie@FreeBSD.org>2017-03-28 06:03:43 +0000
commite8aa125d464be1f250b75f43986fc93a25dfad86 (patch)
treecfb6405e17f0345dcf92c31066d9bf90ae66c7e7
parent9e55018b05bf06a66cff34b38d0513f3e6ce1693 (diff)
downloadFreeBSD-src-e8aa125d464be1f250b75f43986fc93a25dfad86.zip
FreeBSD-src-e8aa125d464be1f250b75f43986fc93a25dfad86.tar.gz
MFC r315686,r315688:
r315686: kvm_geterr: handle `kd` == NULL in a deterministic/graceful manner Return a NUL string instead of just working by accident with kvm_geterr(3) when MALLOC_PRODUCTION is disabled (I didn't confirm the MALLOC_PRODUCTION being enabled path). Document the new explicit return behavior for kvm_geterr(3), as well as the previous implicit behavior, i.e., the buffer attached to returned via kvm_geterr(3) would be empty if a previous error hadn't been stored in `kd`. r315688: kvm_write: fix -Wcast-qual warning in pointer arithmetic argument Cast buf to `const char *` when doing arithmetic operation to match `cp`'s type [1].
-rw-r--r--lib/libkvm/kvm.c7
-rw-r--r--lib/libkvm/kvm_geterr.311
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c
index 2f95a20..d6cc7d8 100644
--- a/lib/libkvm/kvm.c
+++ b/lib/libkvm/kvm.c
@@ -66,6 +66,8 @@ static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94";
SET_DECLARE(kvm_arch, struct kvm_arch);
+static char _kd_is_null[] = "";
+
/* from src/lib/libc/gen/nlist.c */
int __fdnlist(int, struct nlist *);
@@ -113,6 +115,9 @@ kvm_fdnlist(kvm_t *kd, struct kvm_nlist *list)
char *
kvm_geterr(kvm_t *kd)
{
+
+ if (kd == NULL)
+ return (_kd_is_null);
return (kd->errbuf);
}
@@ -932,7 +937,7 @@ kvm_write(kvm_t *kd, u_long kva, const void *buf, size_t len)
len -= cw;
}
- return (cp - (char *)buf);
+ return (cp - (const char *)buf);
}
int
diff --git a/lib/libkvm/kvm_geterr.3 b/lib/libkvm/kvm_geterr.3
index 3ce5c72..4aa9cc8 100644
--- a/lib/libkvm/kvm_geterr.3
+++ b/lib/libkvm/kvm_geterr.3
@@ -32,7 +32,7 @@
.\" @(#)kvm_geterr.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd June 4, 1993
+.Dd March 21, 2017
.Dt KVM_GETERR 3
.Os
.Sh NAME
@@ -54,6 +54,15 @@ library call did not produce an error.
The string returned is stored in memory owned by
.Xr kvm 3
so the message should be copied out and saved elsewhere if necessary.
+.Sh RETURN VALUES
+The function
+.Fn kvm_geterr
+will return "" if
+.Fa kd
+is
+.Dv NULL
+or an error has not been captured for
+.Fa kd .
.Sh SEE ALSO
.Xr kvm 3 ,
.Xr kvm_close 3 ,
OpenPOWER on IntegriCloud