From: Halil Pasic <pasic@linux.ibm.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Thomas Huth <thuth@redhat.com>,
David Hildenbrand <david@redhat.com>,
Cornelia Huck <cohuck@redhat.com>,
qemu-devel@nongnu.org,
Christian Borntraeger <borntraeger@de.ibm.com>,
qemu-s390x@nongnu.org, Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter
Date: Thu, 30 Jul 2020 13:28:12 +0200 [thread overview]
Message-ID: <20200730132812.0a4a4607.pasic@linux.ibm.com> (raw)
In-Reply-To: <20200730102506.GD3477223@redhat.com>
On Thu, 30 Jul 2020 11:25:06 +0100
Daniel P. Berrangé <berrange@redhat.com> wrote:
> > /* make a NUL-terminated string */
> > - loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
> > - loadparm_str[sizeof(ms->loadparm)] = 0;
> > + loadparm_str = g_malloc0(sizeof(ms->loadparm) + 1);
> > + memcpy(loadparm_str, ms->loadparm, sizeof(ms->loadparm));
>
> I feel like g_strndup(ms->loadparm, sizeof(ms->loadparm))
> is what should have been used here.
>
> It copies N characters, but allocates N+1 adding a trailing NUL
> which are the semantic we wanted here.
I agree. Thanks for pointing this out. I'm not very familiar with the
string utilities of glib.
Regards,
Halil
next prev parent reply other threads:[~2020-07-30 11:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 13:02 [PATCH 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter Halil Pasic
2020-07-29 17:09 ` Cornelia Huck
2020-07-29 17:12 ` Peter Maydell
2020-07-30 10:25 ` Daniel P. Berrangé
2020-07-30 11:28 ` Halil Pasic [this message]
2020-07-30 10:26 ` Cornelia Huck
2020-07-30 11:25 ` Halil Pasic
2020-07-30 11:29 ` Cornelia Huck
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=20200730132812.0a4a4607.pasic@linux.ibm.com \
--to=pasic@linux.ibm.com \
--cc=berrange@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=rth@twiddle.net \
--cc=thuth@redhat.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 NNTP newsgroup(s).