NetBSD Problem Report #51003

From www@NetBSD.org  Thu Mar 24 12:31:43 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 7267E7ACAB
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 24 Mar 2016 12:31:43 +0000 (UTC)
Message-Id: <20160324123142.84F507ACAD@mollari.NetBSD.org>
Date: Thu, 24 Mar 2016 12:31:42 +0000 (UTC)
From: dcb314@hotmail.com
Reply-To: dcb314@hotmail.com
To: gnats-bugs@NetBSD.org
Subject: src/lib/libc/time/zic.c:2561]: (error) Uninitialized variable: xr
X-Send-Pr-Version: www-1.0

>Number:         51003
>Category:       lib
>Synopsis:       src/lib/libc/time/zic.c:2561]: (error) Uninitialized variable: xr
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 24 12:35:00 +0000 2016
>Closed-Date:    Tue May 31 03:53:20 +0000 2016
>Last-Modified:  Tue May 31 03:53:20 +0000 2016
>Originator:     David Binderman
>Release:        cvs dated 20160324
>Organization:
>Environment:
>Description:

Source code is

        struct rule xr;
        struct attype *lastat;
        xr.r_month = TM_JANUARY;
        xr.r_dycode = DC_DOM;
        xr.r_dayofmonth = 1;
        xr.r_tod = 0;
        for (lastat = &attypes[0], i = 1; i < timecnt; i++)
            if (attypes[i].at > lastat->at)
                lastat = &attypes[i];
        if (lastat->at < rpytime(&xr, max_year - 1)) {

So local variable xr is only partially initialised when it
is given to rpytime. 

Suggest initialise all fields of xr to something sensible, maybe
with a call to memset, shortly after its declaration.

    memset( &xr, 0, sizeof( xr));




>How-To-Repeat:

>Fix:

>Release-Note:

>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/51003: src/lib/libc/time/zic.c:2561]: (error) Uninitialized variable: xr
Date: Thu, 24 Mar 2016 23:50:27 +0700

     Date:        Thu, 24 Mar 2016 12:35:00 +0000 (UTC)
     From:        dcb314@hotmail.com
     Message-ID:  <20160324123500.B8C777ACBD@mollari.NetBSD.org>

   | So local variable xr is only partially initialised when it
   | is given to rpytime.

 Everything that will be accessed is initialised, so it is OK.

   | Suggest initialise all fields of xr to something sensible, maybe
   | with a call to memset, shortly after its declaration.
   | 
   |     memset( &xr, 0, sizeof( xr));

 But if it is to be invalid (or inappropriate) to pass a pointer to a
 partially uninitialised struct to a function, how can it possibly be
 valid to pass a pointer to a wholly uninitialised struct?

 It is only because you know what memset does with the pointer that this
 is acceptable.   Just as it is that we know what rpytime() does with the
 pointer makes it OK to be init'd just as it is.

 kre

From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51003 CVS commit: src/lib/libc/time
Date: Tue, 31 May 2016 03:47:49 +0000

 Module Name:	src
 Committed By:	dholland
 Date:		Tue May 31 03:47:49 UTC 2016

 Modified Files:
 	src/lib/libc/time: zic.c

 Log Message:
 PR 51003 David Binderman: bzero struct before passing it around.

 This is actually unnecessary as the call in question uses only fields
 that have been set explicitly, but good practice regardless and it's
 not like it's on a performance-critical path.


 To generate a diff of this commit:
 cvs rdiff -u -r1.57 -r1.58 src/lib/libc/time/zic.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: dholland@NetBSD.org
State-Changed-When: Tue, 31 May 2016 03:53:20 +0000
State-Changed-Why:
fixed, thanks


>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.