From: Gustavo Sousa <gustavo.sousa@intel.com>
To: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
Cc: <igt-dev@lists.freedesktop.org>, Ryszard Knop <ryszard.knop@intel.com>
Subject: Re: [PATCH i-g-t] lib/igt_hook: Fix realloc size to avoid memory overwriting
Date: Mon, 29 Jun 2026 19:33:12 -0300 [thread overview]
Message-ID: <874iilt1sn.fsf@intel.com> (raw)
In-Reply-To: <2oskxsgbneasu3zcty4lrikgmbcqg6bdhefkqcorqmpa336mw6@p2gn3cjtkxrd>
Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> writes:
> On Mon, Jun 29, 2026 at 09:17:53AM -0300, Gustavo Sousa wrote:
>> Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> writes:
>>
>> > Doubling test name size might be not enough for realloc if target name
>> > length is larger than test/subtest name size.
>> >
>> > Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
>> > Cc: Gustavo Sousa <gustavo.sousa@intel.com>
>> > Cc: Ryszard Knop <ryszard.knop@intel.com>
>> > ---
>> > lib/igt_hook.c | 2 +-
>> > 1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/lib/igt_hook.c b/lib/igt_hook.c
>> > index b8f25b6c7a..a44b852da1 100644
>> > --- a/lib/igt_hook.c
>> > +++ b/lib/igt_hook.c
>> > @@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, struct
>> > if (len + 1 > *size_ptr) {
>> > size_t fullname_size;
>> >
>> > - *size_ptr *= 2;
>> > + *size_ptr += len + 1;
>>
>> Oops. My bad. Thanks for finding this!
>>
>> Do we need to use "+=" instead of "=" above, though?
>>
>> Also, perhaps we could use roundup_power_of_two(len + 1) to reduce the
>> number of follow-up reallocs?
>
> Sorry, I haven't explained why I used "+=" instead of "=". That was
> first what comes to my mind to fix the issue and try to decrease number
> of reallocs more than with simple '='. For smaller sizes I'm not sure if
> size of power of two is better than any other value. Glibc adds some
> overhead to malloc so I think any strategy we pick which increases
> buffer underneath is acceptable to me.
I just though "+=" adding exactly the size needed as an "extra" looked
odd and didn't initially get that this indeed had the objective of
avoiding extra reallocs in the future. I wonder if future readers of the
code will get the same perception or if that's just me.
--
Gustavo Sousa
>
> --
> Zbigniew
>
>
>>
>> --
>> Gustavo Sousa
>>
>> > *name_ptr = realloc(*name_ptr, *size_ptr);
>> >
>> > fullname_size = igt_hook_calc_test_fullname_size(igt_hook);
>> > --
>> > 2.54.0
next prev parent reply other threads:[~2026-06-29 22:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 11:54 [PATCH i-g-t] lib/igt_hook: Fix realloc size to avoid memory overwriting Zbigniew Kempczyński
2026-06-29 11:59 ` Knop, Ryszard
2026-06-29 12:17 ` Gustavo Sousa
2026-06-29 15:38 ` Zbigniew Kempczyński
2026-06-29 16:32 ` Zbigniew Kempczyński
2026-06-29 22:33 ` Gustavo Sousa [this message]
2026-06-29 12:37 ` Jani Nikula
2026-06-29 12:37 ` Jani Nikula
2026-06-29 15:40 ` Zbigniew Kempczyński
2026-06-29 22:50 ` ✗ Fi.CI.BAT: failure for " Patchwork
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=874iilt1sn.fsf@intel.com \
--to=gustavo.sousa@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=ryszard.knop@intel.com \
--cc=zbigniew.kempczynski@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.