NetBSD Problem Report #56174
From www@netbsd.org Sat May 15 07:09:07 2021
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id D01EF1A9289
for <gnats-bugs@gnats.NetBSD.org>; Sat, 15 May 2021 07:09:07 +0000 (UTC)
Message-Id: <20210515070906.62E691A928A@mollari.NetBSD.org>
Date: Sat, 15 May 2021 07:09:06 +0000 (UTC)
From: mforney@mforney.org
Reply-To: mforney@mforney.org
To: gnats-bugs@NetBSD.org
Subject: libcurses: __makewin() accesses uninitialized WINDOW field
X-Send-Pr-Version: www-1.0
>Number: 56174
>Category: lib
>Synopsis: libcurses: __makewin() accesses uninitialized WINDOW field
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat May 15 07:10:01 +0000 2021
>Closed-Date: Wed Jun 09 02:13:14 +0000 2021
>Last-Modified: Wed Jun 09 05:15:01 +0000 2021
>Originator: Michael Forney
>Release: trunk
>Organization:
>Environment:
>Description:
I noticed the following warning when compiling libcurses/newwin.c:
In file included from libcurses/newwin.c:37:
libcurses/newwin.c: In function '__makenew':
libcurses/curses_private.h:89:29: warning: '*win.battr' may be used uninitialized [-Wmaybe-uninitialized]
89 | ((c).battr) = ((((c).battr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \
| ~~~~^~~~~~~
libcurses/newwin.c:384:9: note: in expansion of macro 'SET_BGWCOL'
384 | SET_BGWCOL(*win, 1);
| ^~~~~~~~~~
I believe this warning is legitimate. The __makenew() function allocates the win structure, and then invokes the SET_BGWCOL macro without previously setting battr.
However, it looks like both callers of __makenew() overwrite the previous value of battr themselves. Additionally, I found no uses of the BGWCOL macro in the libcurses codebase.
>How-To-Repeat:
1. Compile libcurses/newwin.c with -Wall -O2.
2. Observe warning about use of uninitialized field.
>Fix:
If BGWCOL should be set on windows created with __newwin and __subwin, then __makenew() should initialize battr to 0 before invoking SET_BGWCOL, and __newwin/__subwin should take care to preserve it when setting battr.
I am not sure if this fix is correct, but my best attempt at a patch is the following:
diff --git a/lib/libcurses/newwin.c b/lib/libcurses/newwin.c
index 4db46cd..31cee08 100644
--- a/lib/libcurses/newwin.c
+++ b/lib/libcurses/newwin.c
@@ -135,9 +135,7 @@ __newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad,
win->bch = ' ';
if (__using_color)
- win->battr = __default_color;
- else
- win->battr = 0;
+ win->battr |= __default_color;
win->nextp = win;
win->ch_off = 0;
win->orig = NULL;
@@ -377,6 +375,7 @@ __makenew(SCREEN *screen, int nlines, int ncols, int by, int bx, int sub,
win->flags = (__IDLINE | __IDCHAR);
win->delay = -1;
win->wattr = 0;
+ win->battr = 0;
#ifdef HAVE_WCHAR
win->bnsp = NULL;
SET_BGWCOL(*win, 1);
>Release-Note:
>Audit-Trail:
From: "Valeriy E. Ushakov" <uwe@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/56174 CVS commit: src/lib/libcurses
Date: Sat, 15 May 2021 11:06:08 +0000
Module Name: src
Committed By: uwe
Date: Sat May 15 11:06:08 UTC 2021
Modified Files:
src/lib/libcurses: newwin.c
Log Message:
__newwin - fix BGWCOL initialization.
From Michael Forney in PR lib/56174
To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/lib/libcurses/newwin.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->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Wed, 09 Jun 2021 00:48:08 +0000
State-Changed-Why:
is this fixed?
State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Wed, 09 Jun 2021 02:13:14 +0000
State-Changed-Why:
Feedback mail bounced.
From: Michael Forney <mforney@mforney.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: lib/56174 (libcurses: __makewin() accesses uninitialized WINDOW field)
Date: Tue, 8 Jun 2021 20:26:26 -0700
On 2021-06-08, dholland@netbsd.org <dholland@netbsd.org> wrote:
> Synopsis: libcurses: __makewin() accesses uninitialized WINDOW field
>
> State-Changed-From-To: feedback->closed
> State-Changed-By: dholland@NetBSD.org
> State-Changed-When: Wed, 09 Jun 2021 02:13:14 +0000
> State-Changed-Why:
> Feedback mail bounced.
Not sure which mail bounced (I did indeed receive the one asking for
feedback). But, yes, this was fixed.
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: lib/56174 (libcurses: __makewin() accesses uninitialized WINDOW
field)
Date: Wed, 9 Jun 2021 05:10:23 +0000
On Wed, Jun 09, 2021 at 03:30:02AM +0000, Michael Forney wrote:
> > Feedback mail bounced.
>
> Not sure which mail bounced (I did indeed receive the one asking for
> feedback). But, yes, this was fixed.
Hrm. Not sure, went through dozens of bounces tonight, might have
goofed.
--
David A. Holland
dholland@netbsd.org
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.