Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp425652ybv; Thu, 13 Feb 2020 03:09:43 -0800 (PST) X-Google-Smtp-Source: APXvYqwitWVD0ZAUZhQVpSANoly04b///aGCGYF02huHX3GzsMb26kGgP3h/KdAR5c+poB9Yybfk X-Received: by 2002:aca:33d5:: with SMTP id z204mr2373443oiz.120.1581592182944; Thu, 13 Feb 2020 03:09:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581592182; cv=none; d=google.com; s=arc-20160816; b=T5wu77NeX7NEThjxgc5OwNwQo5lkTBpC9JjIEgbbneGONHtcI52uLp+83Lvfowk0a0 TBJQPt71d6+mvkHT7kuG+fbwWoVkqsClWoVwX5mXf5cwZ0oSgH/OlFx20TBz+r4rqys2 9jE38rmtvhr4atL1zCUp+WI93V9MjzUVxEtwLOhSlFMHD2FWSy/YsLQiQf4o4yHjecQ3 l6tTtZpwSyhhy8A2ZeiJJs6Z85x4htg5idww0xiR4Eo7BjPUgNdw+vPCpkhOY7TjuryX 0vNHCXTvt/h1OLrkkv7IBph/JnJh/bCNUd+N0M1R16a0vFjAWNSlOI6D5kxFxbdF1MyL Y40w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=Rh+bWg1peeSmVzyxxXOPGQpNTf1aI4Yae1qitHYFzC0=; b=BYaGk/WruzNcYc2oQAwKVKIpK2WE+BnVvvA0UeP90IgGggFGQDwYzd3zwU3JIB3KKF T02GjSIeLfwqqZgO0T/r3LzEZ+S/QXmHPzrP3K2SCt1Zx0Vjq+BeF5W0OFRrYGUG2ziw n5FBwvZd7jjs44uWEiFMh9z3kVRUJXHKKl6ekZg/tfH5qCqiHiMDY1VnNRHR59a0/wJS Bs4iRq7mjelODzlLhKYRBb3DvxCdkK8kfrO3AvDTOJnTe0D6pEaeptTLtgTCPHQY0FQS P/6OMw2OSd0Gjzb2mCtXzJea8NwY14N4/4cyj2JHqY4n0Kqb+vBv63/5V3dv5wq7PBCY 9l4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18si1020667otp.48.2020.02.13.03.09.23; Thu, 13 Feb 2020 03:09:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729852AbgBMLJV (ORCPT + 99 others); Thu, 13 Feb 2020 06:09:21 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:38266 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729531AbgBMLJU (ORCPT ); Thu, 13 Feb 2020 06:09:20 -0500 Received: by mail-ot1-f68.google.com with SMTP id z9so5170961oth.5; Thu, 13 Feb 2020 03:09:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Rh+bWg1peeSmVzyxxXOPGQpNTf1aI4Yae1qitHYFzC0=; b=kzhbr9MBqncwI+6BAOWb+rhiD9tVNUk4Z2RCOC7+Y0jsF/6BuiNssd4poEdTscvNge 814VqTPT3dRLW+ttil4Eo/aXwnZ8mq3Ok4Wna21Kdwq1aD8AJ4tG/gjGvdlgk8Imvjtf HRXtyJp9mvjjP1Wmmq3GF/EWYKqBirQiKx2lFmgfhBupo7VWi2lqi0fTDDDe9+T31B+5 VJYdv70B0NOjOV2ThgPGLtlgHpDMgN47ZV1qBNvJ78u7PFXyeJYsckxDg2SYUuSQjCYa utziGj8Hw4V4DIIfVxms7KvKfOK0NtBYakbLmd/c0lsW9DtiSQqC9yssvDzhGmk7waDa Extw== X-Gm-Message-State: APjAAAUa9hYxyxmreemfGzRrAALrZ0UGs5pM5yJ9Xga1SwM+bZT3s2GV kouL5oV/CeX4n+HTOROcJgIoIZHGNZ5QRbhD5B1uvu4U X-Received: by 2002:a9d:dc1:: with SMTP id 59mr13000694ots.250.1581592159889; Thu, 13 Feb 2020 03:09:19 -0800 (PST) MIME-Version: 1.0 References: <20200211174126.GA29960@embeddedor> In-Reply-To: <20200211174126.GA29960@embeddedor> From: Geert Uytterhoeven Date: Thu, 13 Feb 2020 12:09:08 +0100 Message-ID: Subject: Re: [PATCH] treewide: Replace zero-length arrays with flexible-array member To: "Gustavo A. R. Silva" Cc: Linux Kernel Mailing List , Kees Cook , "David S. Miller" , Greg KH , Linux Crypto Mailing List , netdev , USB list Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Gustavo, On Tue, Feb 11, 2020 at 10:49 PM Gustavo A. R. Silva wrote: > The current codebase makes use of the zero-length array language > extension to the C90 standard, but the preferred mechanism to declare > variable-length types such as these ones is a flexible array member[1][2], > introduced in C99: > > struct foo { > int stuff; > struct boo array[]; > }; > > By making use of the mechanism above, we will get a compiler warning > in case the flexible array does not occur last in the structure, which > will help us prevent some kind of undefined behavior bugs from being > unadvertenly introduced[3] to the codebase from now on. > > All these instances of code were found with the help of the following > Coccinelle script: > > @@ > identifier S, member, array; > type T1, T2; > @@ > > struct S { > ... > T1 member; > T2 array[ > - 0 > ]; > }; I've stumbled across one more in include/uapi/linux/usb/ch9.h: struct usb_key_descriptor { __u8 bLength; __u8 bDescriptorType; __u8 tTKID[3]; __u8 bReserved; __u8 bKeyData[0]; } __attribute__((packed)); And it seems people are (ab)using one-sized arrays for flexible arrays, too: struct usb_string_descriptor { __u8 bLength; __u8 bDescriptorType; __le16 wData[1]; /* UTF-16LE encoded */ } __attribute__ ((packed)); As this is UAPI, we have to be careful for regressions, though. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds