alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] ALSA: vmaster: Use flex_array_size() helper in memcpy()
@ 2020-07-29 22:18 Gustavo A. R. Silva
  2020-07-30  8:41 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2020-07-29 22:18 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai
  Cc: alsa-devel, linux-kernel, Gustavo A. R. Silva

Make use of the flex_array_size() helper to calculate the size of a
flexible array member within an enclosing structure.

This helper offers defense-in-depth against potential integer overflows
and makes it explicitly clear that we are dealing with a flexible array
member.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 sound/core/vmaster.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
index ab36f9898711..21ce4082cb5f 100644
--- a/sound/core/vmaster.c
+++ b/sound/core/vmaster.c
@@ -262,7 +262,8 @@ int _snd_ctl_add_follower(struct snd_kcontrol *master,
 		return -ENOMEM;
 	srec->kctl = follower;
 	srec->follower = *follower;
-	memcpy(srec->follower.vd, follower->vd, follower->count * sizeof(*follower->vd));
+	memcpy(srec->follower.vd, follower->vd, flex_array_size(srec, follower.vd,
+								srec->follower.count));
 	srec->master = master_link;
 	srec->flags = flags;
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-30 14:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 22:18 [PATCH][next] ALSA: vmaster: Use flex_array_size() helper in memcpy() Gustavo A. R. Silva
2020-07-30  8:41 ` Takashi Iwai
2020-07-30 13:12   ` Gustavo A. R. Silva
2020-07-30 14:57     ` Takashi Iwai

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).