From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Vitaly Chikunov <vt@altlinux.org>, Greg Kurz <groug@kaod.org>,
ldv@altlinux.org, qemu-stable@nongnu.org
Subject: Re: [PATCH] 9pfs: Fix segfault in do_readdir_many caused by struct dirent overread
Date: Fri, 28 Jan 2022 15:49:07 +0100 [thread overview]
Message-ID: <2086833.qgTTZoEYMS@silver> (raw)
In-Reply-To: <2533498.9Ea8Rob0xc@silver>
On Freitag, 28. Januar 2022 15:43:10 CET Christian Schoenebeck wrote:
> Also I would prefer g_malloc0() over g_malloc().
Never mind about that one. g_malloc0() with immediate subsequent memcpy() and
exact same size argument would be pointless.
> Then by adding a variable for the d_reclen yes/no case, overall code can be
> reduced. So I would suggest something like this instead:
>
> struct dirent *
> qemu_dirent_dup(struct dirent *dent)
> {
> #if defined _DIRENT_HAVE_D_RECLEN
> /* Avoid use of strlen() if there's d_reclen. */
> const size_t sz = dent->d_reclen;
> #else
> /* Fallback to a most portable way. */
> const size_t sz = offsetof(struct dirent, d_name) +
> strlen(dent->d_name) + 1;
> #endif
> struct dirent *dst = g_malloc(sz);
> return memcpy(dst, dent, sz);
> }
Best regards,
Christian Schoenebeck
next prev parent reply other threads:[~2022-01-28 14:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-27 21:27 [PATCH] 9pfs: Fix segfault in do_readdir_many caused by struct dirent overread Vitaly Chikunov
2022-01-28 14:43 ` Christian Schoenebeck
2022-01-28 14:49 ` Christian Schoenebeck [this message]
2022-01-28 16:24 ` Vitaly Chikunov
2022-01-28 17:40 ` Christian Schoenebeck
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=2086833.qgTTZoEYMS@silver \
--to=qemu_oss@crudebyte.com \
--cc=groug@kaod.org \
--cc=ldv@altlinux.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=vt@altlinux.org \
/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).