From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: Qing Zhao <qing.zhao@oracle.com>
Cc: Kees Cook <keescook@chromium.org>,
jakub Jelinek <jakub@redhat.com>,
Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: One question on the source code of tree-object-size.cc
Date: Fri, 4 Aug 2023 10:42:50 -0400 [thread overview]
Message-ID: <bcf60498-fcd5-fca6-8c0d-dc537b4e5ff2@gotplt.org> (raw)
In-Reply-To: <ad89240a-5067-d72f-5b34-e03ab14cae25@gotplt.org>
On 2023-08-04 10:40, Siddhesh Poyarekar wrote:
> On 2023-08-03 13:34, Qing Zhao wrote:
>> One thing I need to point out first is, currently, even for regular
>> fixed size array in the structure,
>> We have this same issue, for example:
>>
>> #define LENGTH 10
>>
>> struct fix {
>> size_t foo;
>> int array[LENGTH];
>> };
>>
>> …
>> int main ()
>> {
>> struct fix *p;
>> p = alloc_buf_more ();
>>
>> expect(__builtin_object_size(p->array, 1), LENGTH * sizeof(int));
>> expect(__builtin_object_size(p->array, 0), -1);
>> }
>>
>> Currently, for __builtin_object_size(p->array, 0), GCC return UNKNOWN
>> for it.
>> This is not a special issue for flexible array member.
>
> That's fine for fixed arrays at the end of a struct because the "whole
> object" size could be anything; `p` could be pointing to the beginning
> of an array for all we know. If however `array` is strictly a flex
> array, i.e.:
>
> ```
> struct A
> {
> size_t foo;
> int array[];
> };
> ```
>
> then there's no way in valid C to have an array of `struct fix`, so `q`
> must be pointing to a single element. So you could deduce:
>
> 1. the minimum size of the whole object that q points to.
Actually for minimum size we'd also need a guarantee that
`alloc_buf_more` returns a valid allocated object.
Sid
next prev parent reply other threads:[~2023-08-04 14:42 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 16:47 Qing Zhao
2023-07-31 17:03 ` Siddhesh Poyarekar
2023-07-31 17:07 ` Siddhesh Poyarekar
2023-07-31 18:13 ` Qing Zhao
2023-07-31 18:23 ` Siddhesh Poyarekar
2023-07-31 18:36 ` Qing Zhao
2023-08-01 21:35 ` Qing Zhao
2023-08-01 22:57 ` Kees Cook
2023-08-02 0:29 ` Siddhesh Poyarekar
2023-08-02 14:02 ` Qing Zhao
2023-08-03 16:15 ` Siddhesh Poyarekar
2023-08-03 16:43 ` Qing Zhao
2023-08-03 17:19 ` Siddhesh Poyarekar
2023-08-03 17:34 ` Qing Zhao
2023-08-03 17:51 ` Kees Cook
2023-08-03 19:55 ` Qing Zhao
2023-08-04 7:37 ` Kees Cook
2023-08-03 21:31 ` Qing Zhao
2023-08-04 7:38 ` Kees Cook
2023-08-04 13:32 ` Qing Zhao
2023-08-04 14:40 ` Siddhesh Poyarekar
2023-08-04 14:42 ` Siddhesh Poyarekar [this message]
2023-08-04 15:27 ` Qing Zhao
2023-08-04 15:27 ` Qing Zhao
2023-08-04 16:36 ` Siddhesh Poyarekar
2023-08-04 19:06 ` Qing Zhao
2023-08-04 19:09 ` Siddhesh Poyarekar
2023-08-04 19:26 ` Qing Zhao
2023-08-02 0:21 ` Siddhesh Poyarekar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bcf60498-fcd5-fca6-8c0d-dc537b4e5ff2@gotplt.org \
--to=siddhesh@gotplt.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=keescook@chromium.org \
--cc=qing.zhao@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).