From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Jani Nikula <jani.nikula@linux.intel.com>, igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t] debugfs: Fix writing an extra zero out of bounds in igt_crc_to_string_extended()
Date: Fri, 1 Feb 2019 10:55:04 +0100 [thread overview]
Message-ID: <061997f6-bf31-6217-fc1a-e221b0d4e49c@linux.intel.com> (raw)
In-Reply-To: <87womjyhjs.fsf@intel.com>
Op 01-02-2019 om 10:38 schreef Jani Nikula:
> On Thu, 31 Jan 2019, Maarten Lankhorst <maarten.lankhorst@linux.intel.com> wrote:
>> Op 28-01-2019 om 13:24 schreef Jani Nikula:
>>> On Mon, 28 Jan 2019, Maarten Lankhorst <maarten.lankhorst@linux.intel.com> wrote:
>>>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>>>> ---
>>>> lib/igt_debugfs.c | 8 ++++----
>>>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
>>>> index 3656c66a5674..d1fc0ff7f710 100644
>>>> --- a/lib/igt_debugfs.c
>>>> +++ b/lib/igt_debugfs.c
>>>> @@ -458,17 +458,17 @@ char *igt_crc_to_string_extended(igt_crc_t *crc, char delimiter, int crc_size)
>>>> int i;
>>>> int len = 0;
>>>> int field_width = 2 * crc_size; /* Two chars per byte. */
>>>> - char *buf = malloc((field_width+1) * crc->n_words * sizeof(char));
>>>> + char *buf = malloc((field_width+1) * crc->n_words);
>>>>
>>>> if (!buf)
>>>> return NULL;
>>>>
>>>> - for (i = 0; i < crc->n_words; i++)
>>>> + for (i = 0; i < crc->n_words - 1; i++)
>>>> len += sprintf(buf + len, "%0*x%c", field_width,
>>>> crc->crc[i], delimiter);
>>> Or keep the loop condition and make this:
>>>
>>> len += sprintf(buf + len, "%s%0*x", i ? &delimiter : "",
>>> field_width, crc->crc[i]);
>>>
>>> Additionally could make the delimiter passed here a char*.
>> That is also a valid solution. :) Is it ok to go with the solution I
>> proposed or do you have a strong preference for that?
>>
>> I don't think we can just pass &delimiter, we would depend on the next
>> byte in memory accidentally being \0.
> D'oh. Yeah, you'd have to pass the delimiter as a string to make this
> really work, or add a local buf. Meh. Something for the future.
>
> On the original patch,
>
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
>
>
>
>
Thanks, pushed. :)
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2019-02-01 9:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-28 11:54 [igt-dev] [PATCH i-g-t] debugfs: Fix writing an extra zero out of bounds in igt_crc_to_string_extended() Maarten Lankhorst
2019-01-28 12:24 ` Jani Nikula
2019-01-31 16:14 ` Maarten Lankhorst
2019-02-01 9:38 ` Jani Nikula
2019-02-01 9:55 ` Maarten Lankhorst [this message]
2019-01-28 13:18 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2019-01-28 16:30 ` [igt-dev] ✓ Fi.CI.IGT: " 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=061997f6-bf31-6217-fc1a-e221b0d4e49c@linux.intel.com \
--to=maarten.lankhorst@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jani.nikula@linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox