Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Mar 2017 19:02:17 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r315686 - head/lib/libkvm
Message-ID:  <201703211902.v2LJ2HZL068540@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Tue Mar 21 19:02:17 2017
New Revision: 315686
URL: https://svnweb.freebsd.org/changeset/base/315686

Log:
  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`.
  
  Differential Revision:	D10022
  MFC after:	1 week
  Reviewed by:	vangyzen
  Sponsored by:	Dell EMC Isilon

Modified:
  head/lib/libkvm/kvm.c
  head/lib/libkvm/kvm_geterr.3

Modified: head/lib/libkvm/kvm.c
==============================================================================
--- head/lib/libkvm/kvm.c	Tue Mar 21 18:02:14 2017	(r315685)
+++ head/lib/libkvm/kvm.c	Tue Mar 21 19:02:17 2017	(r315686)
@@ -66,9 +66,14 @@ static char sccsid[] = "@(#)kvm.c	8.2 (B
 
 SET_DECLARE(kvm_arch, struct kvm_arch);
 
+static char _kd_is_null[] = "";
+
 char *
 kvm_geterr(kvm_t *kd)
 {
+
+	if (kd == NULL)
+		return (_kd_is_null);
 	return (kd->errbuf);
 }
 

Modified: head/lib/libkvm/kvm_geterr.3
==============================================================================
--- head/lib/libkvm/kvm_geterr.3	Tue Mar 21 18:02:14 2017	(r315685)
+++ head/lib/libkvm/kvm_geterr.3	Tue Mar 21 19:02:17 2017	(r315686)
@@ -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 ,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703211902.v2LJ2HZL068540>