From nobody@FreeBSD.org  Thu May 15 22:44:18 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 0BDA52F2
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 15 May 2014 22:44:18 +0000 (UTC)
Received: from cgiserv.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client did not present a certificate)
	by mx1.freebsd.org (Postfix) with ESMTPS id ED91B2BCA
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 15 May 2014 22:44:17 +0000 (UTC)
Received: from cgiserv.freebsd.org ([127.0.1.6])
	by cgiserv.freebsd.org (8.14.8/8.14.8) with ESMTP id s4FMiGNQ090510
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 15 May 2014 22:44:16 GMT
	(envelope-from nobody@cgiserv.freebsd.org)
Received: (from nobody@localhost)
	by cgiserv.freebsd.org (8.14.8/8.14.8/Submit) id s4FMiGIh090509;
	Thu, 15 May 2014 22:44:16 GMT
	(envelope-from nobody)
Message-Id: <201405152244.s4FMiGIh090509@cgiserv.freebsd.org>
Date: Thu, 15 May 2014 22:44:16 GMT
From: Myron Walker <myron.walker@emc.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: UnNecessary Copy of Error Buffer in _kvm_open
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         189845
>Category:       kern
>Synopsis:       [kvm] UnNecessary Copy of Error Buffer in _kvm_open
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 15 22:50:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Sun May 18 22:10:00 UTC 2014
>Originator:     Myron Walker
>Release:        
>Organization:
EMC
>Environment:
mwwsoftcluster0# uname -a
FreeBSD mwwsoftcluster0 11.0-CURRENT FreeBSD 11.0-CURRENT #0: Mon May  5 10:30:09 PDT 2014     root@bsd10build01.west.isilon.com:/build/mnt/obj/build/mnt/src/sys/IQ.amd64.debug  amd64

>Description:
_kvm_open in libkvm always returns 0 on a failure.  So writing a message to kd is pointless because it is immediately passed to kvm_close() and the memory is freed.  Se the code snippet below from _kvm_open.

        /*
	 * Copy out the error if doing sane error semantics.
	 */
	if (errout != 0)
		strlcpy(errout, kd->errbuf, _POSIX2_LINE_MAX);
	(void)kvm_close(kd);
	return (0);
>How-To-Repeat:

>Fix:
All error message code can be removed from _kvm_open because none of it is used anyway.

>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, myron.walker@emc.com
Cc:  
Subject: Re: kern/189845: [kvm] UnNecessary Copy of Error Buffer in _kvm_open
Date: Mon, 19 May 2014 00:05:07 +0200

 In FreeBSD PR kern/189845, you wrote:
 > _kvm_open in libkvm always returns 0 on a failure. So writing a
 > message to kd is pointless because it is immediately passed to
 > kvm_close() and the memory is freed. Se the code snippet below from
 > _kvm_open.
 
 >	/*
 >	 * Copy out the error if doing sane error semantics.
 >	 */
 >	if (errout != 0)
 >		strlcpy(errout, kd->errbuf, _POSIX2_LINE_MAX);
 >	(void)kvm_close(kd);
 >	return (0);
 
 The error message is written to errout (if _kvm_open() was called via
 kvm_openfiles()), which stays around.
 
 It may be a bit strange to write an error message to kd->errbuf first
 and then copy it to the user's buffer, but it works fine and may
 slightly reduce code duplication from the two types of error handling
 available to the API client.
 
 -- 
 Jilles Tjoelker
>Unformatted:
