From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 580C63858C83 for ; Thu, 1 Dec 2022 17:18:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 580C63858C83 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-x633.google.com with SMTP id jn7so2228178plb.13 for ; Thu, 01 Dec 2022 09:18:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=PzCj++yI/yShjwhBkpVDE8LyF9buZN6cC50jlwqzt5M=; b=fsWk/Q9BTmiaQraMcOGyLTINH9HCsnGWqMhfjyOgVEpeU6tdrbYztBMSl1vfTdRMF/ K82o7891btK0thwxhosfQsJxg7udMSp7ntpQIw4vqSOpvTMk6EeISu2o3p98U06XKGv3 RFh7nIQHhql8u8B7ZS9Liq5IgdKjT3Yy/f9rw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PzCj++yI/yShjwhBkpVDE8LyF9buZN6cC50jlwqzt5M=; b=DRXjDkUC/l7pfUQg6SGm6pRBYJ/+E07L/6x6xE/KQeV9fH/FVaNv9IWk4UFS1QJ5Vv eDoIQfp+Y+MIIOMYCz3mFYf2AY/xdgCg6GGGIALEHhCHpDNJPun4vk74PIQiQRwEE8Lp GjT/lx09KCwFBZZ3sCJM/4vmBFo/bQVtm+BwaLLE/L3PthF1evfpXzqNj93Y9IZd5PC/ Z8zQzWHBa56lEmmWAWpV/6R+Mw3CTp7MNW5EG+Ef9Wqnclgl+rvrYGkSyWWh0iziUTqz GH0ZDYyuM0BtoCItOZiGvhWFenboIL9/Unh7uNh1K7wmXTnoijlsjXt68KQlUft1nYk1 wO/g== X-Gm-Message-State: ANoB5pmRD4GpVEHF761pe0cvKrPwS2IMlfcsTxgFcbugBnOyMBqO0LRE KbvxARP0uDuMD2DCHnmBIcqxEQ== X-Google-Smtp-Source: AA0mqf72h8fJ2bGZvEX2Vvh4JSMHKgXwy9TpwBYxCd6as2S7W1TXBd5YAZWC09I2FxInSYJUevnLtQ== X-Received: by 2002:a17:902:d4c8:b0:188:a40b:47cd with SMTP id o8-20020a170902d4c800b00188a40b47cdmr49547838plg.72.1669915086309; Thu, 01 Dec 2022 09:18:06 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x6-20020a623106000000b005745eb7eccasm3476681pfx.112.2022.12.01.09.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 09:18:05 -0800 (PST) Date: Thu, 1 Dec 2022 09:18:04 -0800 From: Kees Cook To: Qing Zhao Cc: Richard Biener , "joseph@codesourcery.com" , gcc Patches , "siddhesh@gcc.gnu.org" Subject: Re: [V2][PATCH 1/1] Add a new warning option -Wstrict-flex-arrays. Message-ID: <202212010916.57586DA@keescook> References: <20221130142556.3079865-1-qing.zhao@oracle.com> <20221130142556.3079865-2-qing.zhao@oracle.com> <202212010840.C963E72661@keescook> <39768BBD-9500-41EA-A68F-801B36F051EE@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <39768BBD-9500-41EA-A68F-801B36F051EE@oracle.com> X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Dec 01, 2022 at 05:04:02PM +0000, Qing Zhao wrote: > > > > On Dec 1, 2022, at 11:42 AM, Kees Cook wrote: > > > > On Wed, Nov 30, 2022 at 02:25:56PM +0000, Qing Zhao wrote: > >> '-Wstrict-flex-arrays' > >> Warn about inproper usages of flexible array members according to > >> the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to > >> the trailing array field of a structure if it's available, > >> otherwise according to the LEVEL of the option > >> '-fstrict-flex-arrays=LEVEL'. > >> > >> This option is effective only when LEVEL is bigger than 0. > >> Otherwise, it will be ignored with a warning. > >> > >> when LEVEL=1, warnings will be issued for a trailing array > >> reference of a structure that have 2 or more elements if the > >> trailing array is referenced as a flexible array member. > >> > >> when LEVEL=2, in addition to LEVEL=1, additional warnings will be > >> issued for a trailing one-element array reference of a structure if > >> the array is referenced as a flexible array member. > >> > >> when LEVEL=3, in addition to LEVEL=2, additional warnings will be > >> issued for a trailing zero-length array reference of a structure if > >> the array is referenced as a flexible array member. > >> > >> At the same time, -Warray-bounds is updated: > > > > Why is there both -Wstrict-flex-arrays and -Warray-bounds? I thought > > only the latter was going to exist? > > Yes, It’s very easy to merge these two warnings into one: > > -Warray-bounds, when combined with -fstrict-flex-arrays, in addition to report all the out-of-bounds warnings, it also report > the misuse of flexible array members according to the LEVEL of -fstrict-flex-arrays > > The major question is, do we need one separate warning option to report the misuse of flexible array member only? > If so, then we need to add a new one. I guess it is up to you, but I think it just makes things needlessly complex. I think having 1 option for behavior (-ftrict-flex-arrays), and 1 option for warnings (-Warray-bounds) is sufficient. I think adding -Wstrict-flex-arrays is confusing. -- Kees Cook