lkml.org 
[lkml]   [2023]   [Oct]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] comedi: Annotate struct comedi_lrange with __counted_by
On October 1, 2023 12:45:41 AM PDT, Julia Lawall <julia.lawall@inria.fr> wrote:
>
>
>On Sat, 30 Sep 2023, Kees Cook wrote:
>
>> On Sat, Sep 30, 2023 at 11:14:47AM +0200, Christophe JAILLET wrote:
>> > Prepare for the coming implementation by GCC and Clang of the __counted_by
>> > attribute. Flexible array members annotated with __counted_by can have
>> > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
>> > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
>> > functions).
>> >
>> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> > ---
>> > This patch is part of a work done in parallel of what is currently worked
>> > on by Kees Cook.
>> >
>> > My patches are only related to corner cases that do NOT match the
>> > semantic of his Coccinelle script[1].
>>
>> Nice!
>>
>> struct comedi_lrange {
>> int length;
>> struct comedi_krange range[];
>> };
>> ...
>> static const struct comedi_lrange range_rti800_ai_10_bipolar = {
>> 4, {
>> BIP_RANGE(10),
>> BIP_RANGE(1),
>> BIP_RANGE(0.1),
>> BIP_RANGE(0.02)
>> }
>> };
>>
>> I'm struggling to come up with a way for Coccinelle to find this kind of
>> thing in other places...
>
>Kees, what exactly are you trying to match? Static allocations?

I need to count the number of initialized elements in the flexible array that is the last member and see if it matches a value set in another member.

E.g. the above sets 4 values for the last array member and then sets another member to 4.

-Kees


--
Kees Cook

\
 
 \ /
  Last update: 2023-10-01 17:28    [W:1.239 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site