NetBSD Problem Report #50909

From www@NetBSD.org  Mon Mar  7 12:15:57 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8303F7ABE5
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  7 Mar 2016 12:15:57 +0000 (UTC)
Message-Id: <20160307121556.A65907ACC0@mollari.NetBSD.org>
Date: Mon,  7 Mar 2016 12:15:56 +0000 (UTC)
From: dcb314@hotmail.com
Reply-To: dcb314@hotmail.com
To: gnats-bugs@NetBSD.org
Subject: src/sbin/ifconfig/env.c: 2 * clumsy call to memset ?
X-Send-Pr-Version: www-1.0

>Number:         50909
>Category:       bin
>Synopsis:       src/sbin/ifconfig/env.c: 2 * clumsy call to memset ?
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 07 12:20:00 +0000 2016
>Closed-Date:    Mon Mar 07 13:24:59 +0000 2016
>Last-Modified:  Mon Mar 07 19:15:01 +0000 2016
>Originator:     David Binderman
>Release:        cvs dated 20160305
>Organization:
>Environment:
>Description:

1.

[src/sbin/ifconfig/env.c:145]: (performance) Buffer 'buf' is being written before its old content has been used.

Source code is

    memset(buf, 0, buflen);
    memcpy(buf, prop_data_data_nocopy(data), datalen);

Maybe better code

   memcpy(buf, prop_data_data_nocopy(data), datalen);
   memset(buf + datalen, 0, buflen - datalen);


>How-To-Repeat:

>Fix:

>Release-Note:

>Audit-Trail:
From: David Binderman <dcb314@hotmail.com>
To: "gnats-bugs@NetBSD.org" <gnats-bugs@netbsd.org>
Cc: 
Subject: RE: bin/50909: src/sbin/ifconfig/env.c: 2 * clumsy call to memset ?
Date: Mon, 7 Mar 2016 12:26:06 +0000

 Hello there=2C=0A=
 =0A=
 ----------------------------------------=0A=
 > From: gnats-admin@netbsd.org=0A=
 > To: dcb314@hotmail.com=0A=
 > Subject: Re: bin/50909: src/sbin/ifconfig/env.c: 2 * clumsy call to memse=
 t ?=0A=
 > Date: Mon=2C 7 Mar 2016 12:20:00 +0000=0A=
 >=0A=
 > Thank you very much for your problem report.=0A=
 > It has the internal identification `bin/50909'.=0A=
 > The individual assigned to look at your=0A=
 > report is: bin-bug-people.=0A=
 >=0A=
 >>Category: bin=0A=
 >>Responsible: bin-bug-people=0A=
 >>Synopsis: src/sbin/ifconfig/env.c: 2 * clumsy call to memset ?=0A=
 >>Arrival-Date: Mon Mar 07 12:20:00 +0000 2016=0A=
 >=0A=
 =0A=
 I should have mentioned the second clumsy call:=0A=
 =0A=
 [src/sbin/ifconfig/env.c:166]: (performance) Buffer 'buf' is being written =
 before its old content has been used.=0A=
 =0A=
 Source code is=0A=
 =0A=
 =A0=A0=A0 memset(buf=2C 0=2C buflen)=3B=0A=
 =A0=A0=A0 memcpy(buf=2C prop_data_data_nocopy(data)=2C datalen)=3B=0A=
 =0A=
 This looks like a duplicate of the earlier code.=0A=
 =0A=
 =0A=
 Regards=0A=
 =0A=
 David Binderman=0A=
  		 	   		  =

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50909 CVS commit: src/sbin/ifconfig
Date: Mon, 7 Mar 2016 07:48:53 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Mon Mar  7 12:48:53 UTC 2016

 Modified Files:
 	src/sbin/ifconfig: env.c

 Log Message:
 PR/50909: David Binderman: Optimize memset


 To generate a diff of this commit:
 cvs rdiff -u -r1.9 -r1.10 src/sbin/ifconfig/env.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Mon, 07 Mar 2016 13:24:59 +0000
State-Changed-Why:
Fixed by christos, thanks.


From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50909 CVS commit: src/sbin/ifconfig
Date: Mon, 7 Mar 2016 10:56:17 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Mon Mar  7 15:56:17 UTC 2016

 Modified Files:
 	src/sbin/ifconfig: env.c

 Log Message:
 PR/50909: David Binderman: Optimize memset


 To generate a diff of this commit:
 cvs rdiff -u -r1.10 -r1.11 src/sbin/ifconfig/env.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: David Young <dyoung@pobox.com>
To: gnats-bugs@NetBSD.org, christos@netbsd.org, dcb314@hotmail.com
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: bin/50909: src/sbin/ifconfig/env.c: 2 * clumsy call to memset ?
Date: Mon, 7 Mar 2016 13:12:38 -0600

 On Mon, Mar 07, 2016 at 12:20:00PM +0000, dcb314@hotmail.com wrote:
 > >Number:         50909
 > >Category:       bin
 > >Synopsis:       src/sbin/ifconfig/env.c: 2 * clumsy call to memset ?
 > 
 > [src/sbin/ifconfig/env.c:145]: (performance) Buffer 'buf' is being written before its old content has been used.
 > 
 > Source code is
 > 
 >     memset(buf, 0, buflen);
 >     memcpy(buf, prop_data_data_nocopy(data), datalen);
 > 
 > Maybe better code
 >    
 >    memcpy(buf, prop_data_data_nocopy(data), datalen);
 >    memset(buf + datalen, 0, buflen - datalen);

 Hold on a minute.  The previous code was simpler and more obviously
 harmless.  Is this change *really* justified on performance grounds? :-)

 Dave

 -- 
 David Young
 dyoung@pobox.com    Urbana, IL    (217) 721-9981

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.