Skip to contentSkip to conversation

ALSA: ump: Avoid dereference with max_src_size=0

PATCH New Takashi Iwai 1 participant 1 message Oct 2 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: ump: Avoid dereference with max_src_size=0

safe_copy_string() refers the source pointer for a NUL terminator before verifying the source size. When max_src_size=0, it may dereference wrongly. Fix the verification order.

Only hypothetical hardening, and we see no actual issue in the current code, as they are all valid sources.

Fixes e3f035edadcc ("ALSA: ump: Copy FB name string more safely")
---
 sound/core/ump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/ump.c +1 -1
index 3d1a2ed3b476..f6482a9bfe61 100644
@@ -66,7 +66,7 @@ static void safe_copy_string(void *dst, size_t max_dst_size,
 
 	if (!max_dst_size--)
 		return;
-	for (s = src; max_dst_size && *s && max_src_size--; s++) {
+	for (s = src; max_dst_size && max_src_size-- && *s; s++) {
 		if (!isascii(*s) || !isprint(*s))
 			continue;
 		*d++ = *s;
Signature · 1 line
2.55.0