Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Oct 2003 14:08:33 -0400 (EDT)
From:      Ted Nolan <ted@erg.sri.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        ted@erg.sri.com
Subject:   docs/57669: IFMIB(4) man page uses sysctl(3) incorrectly in example code
Message-ID:  <200310061808.h96I8Xds019326@colanix0.ga.erg.sri.com>
Resent-Message-ID: <200310061810.h96IABES066982@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         57669
>Category:       docs
>Synopsis:       IFMIB(4) man page uses sysctl(3) incorrectly in example code
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 06 11:10:10 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Ted Nolan
>Release:        FreeBSD 4.6.2-RELEASE i386
>Organization:
SRI International
>Environment:
System: FreeBSD colanix0 4.6.2-RELEASE FreeBSD 4.6.2-RELEASE #0: Wed Aug 14 21:23:26 GMT 2002 murray@builder.freebsdmall.com:/usr/src/sys/compile/GENERIC i386


	
>Description:

The man page for ifmib(4) gives a code sample defining a function
get_ifmib_general().  This function uses the sysctl(3) function, but
with incorrect parameters.  The 4th parameter to sysctl(3) is the
_address_ of a location to read and store the size of the data;
however the example code places the actual size here, not the _location_
of the size.  The code will therefore give compilation warnings and
likely fail if run.

>How-To-Repeat:
Enter the code from the example, attempt to compile it with warnings
enabled.
>Fix:

One way to fix it would be to declare a variable
	size_t len;

and replace the given sysctl() line with 2 lines:

	len = sizeof(*ifmd);
	return sysctl(name, 6, ifmd, &len, (void *)0, 0);
>Release-Note:
>Audit-Trail:
>Unformatted:



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