qemu-stable
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] 9pfs: Fix segfault in do_readdir_many caused by struct diren


From: Christian Schoenebeck
Subject: Re: [PATCH] 9pfs: Fix segfault in do_readdir_many caused by struct dirent overread
Date: Fri, 28 Jan 2022 15:49:07 +0100

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]