Bug 189845 - [kvm] UnNecessary Copy of Error Buffer in _kvm_open
Summary: [kvm] UnNecessary Copy of Error Buffer in _kvm_open
Status: Closed Not A Bug
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 1.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-15 23:50 UTC by myron.walker
Modified: 2021-01-11 15:34 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description myron.walker 2014-05-15 23:50:00 UTC
_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);

Fix: 

All error message code can be removed from _kvm_open because none of it is used anyway.
Comment 1 Jilles Tjoelker freebsd_committer 2014-05-18 23:05:07 UTC
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
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:23 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 3 Mark Johnston freebsd_committer 2021-01-11 15:34:25 UTC
Closing per comment 1.