[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

Kees Cook via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 9 09:23:47 PST 2024


kees wrote:

Thanks! The update fixes the anon struct issue I hit. I've found one more issue, though this appears to be a miscalculation with a pathological `count` value (i.e. `count` is signed type and contains a negative value):

```
struct annotated {
    unsigned long flags;
    int count;
    int array __counted_by(count);
};

static struct annotated * noinline alloc_annotated(int index)
{
        struct annotated *p;

        p = malloc(sizeof(*p) + index * sizeof(*p->array));
        p->count = index;

        return p;
}

...
       struct annotated *a;

      c = alloc_annotated(index);
       c->count = -1;
       printf("%zu\n", __builtin_dynamic_object_size(p->array, 1));
```

This prints a wrapped calculation instead of the expected "0".

https://github.com/llvm/llvm-project/pull/76348


More information about the cfe-commits mailing list