NetBSD Problem Report #58912

From www@netbsd.org  Wed Dec 18 01:54:20 2024
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)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 0C8DE1A9238
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 18 Dec 2024 01:54:20 +0000 (UTC)
Message-Id: <20241218015418.A44CD1A923A@mollari.NetBSD.org>
Date: Wed, 18 Dec 2024 01:54:18 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: ctype(3) abuse detection fails for variable references
X-Send-Pr-Version: www-1.0

>Number:         58912
>Category:       lib
>Synopsis:       ctype(3) abuse detection fails for variable references
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 18 01:55:00 +0000 2024
>Last-Modified:  Wed Dec 18 12:10:55 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9?
>Organization:
The isnetbsd Foundation
>Environment:
>Description:
The ctype(3) abuse detection trick with -Wchar-subscripts works when
the input is an array element, pointer dereference, or function call,
but not when it's a variable reference:

$ cat foo.c
#include <ctype.h>
extern char x;
int f(void) { return isspace(x); }
$ cat bar.c
#include <ctype.h>
extern char x[];
int f(void) { return isspace(x[0]); }
$ cc -c -Wall -Werror foo.c
$ cc -c -Wall -Werror bar.c
In file included from /usr/include/ctype.h:100,
                 from bar.c:1:
bar.c: In function 'f':
bar.c:3:31: error: array subscript has type 'char' [-Werror=char-subscripts]
    3 | int f(void) { return isspace(x[0]); }
      |                               ^
cc1: all warnings being treated as errors

Expected both cc invocations to report warning.
>How-To-Repeat:

>Fix:
Yes, please!

Putting

#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wsystem-headers"
...
#pragma GCC diagnostic pop

around the definitions in sys/ctype_inline.h may work but may also
have side effects I haven't thought of yet.

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58912 CVS commit: src
Date: Wed, 18 Dec 2024 02:47:01 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Wed Dec 18 02:47:00 UTC 2024

 Modified Files:
 	src/distrib/sets/lists/tests: mi
 	src/tests/usr.bin/cc: Makefile
 Added Files:
 	src/tests/usr.bin/cc: t_ctype_abuse.sh

 Log Message:
 tests/usr.bin/cc: Add test for ctype(3) detection.

 PR lib/58912: ctype(3) abuse detection fails for variable references


 To generate a diff of this commit:
 cvs rdiff -u -r1.1350 -r1.1351 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/cc/Makefile
 cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/cc/t_ctype_abuse.sh

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

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.