Skip to contentSkip to conversation

ucm: Use strncmp to avoid access-out-of-boundary

PATCH Applied Chih-Yang Hsia 2 participants 2 messages Nov 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ucm: Use strncmp to avoid access-out-of-boundary

From: paulhsia <[email protected]>

If the length of the identifier is less than the length of the prefix, access-out-of-boundary will occur in memcmp().

---
 src/ucm/main.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
src/ucm/main.c +5 -3
index b0b6ffb3..252e50d9 100644
@@ -61,11 +61,13 @@ static int check_identifier(const char *identifier, const char *prefix)
 {
 	int len;
 
-	if (strcmp(identifier, prefix) == 0)
-		return 1;
 	len = strlen(prefix);
-	if (memcmp(identifier, prefix, len) == 0 && identifier[len] == '/')
+	if (strncmp(identifier, prefix, len) != 0)
+		return 0;
+
+	if (identifier[len] == 0 || identifier[len] == '/')
 		return 1;
+
 	return 0;
 }
 
Signature · 6 lines
2.24.0.393.g34dc348eaf-goog

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#1 lore raw

Dne 29. 11. 19 v 20:35 Chih-Yang Hsia napsal(a):

Quoted 4 lines

From: paulhsia <[email protected]>

If the length of the identifier is less than the length of the prefix, access-out-of-boundary will occur in memcmp().

Applied. Thank you for your contribution.

Jaroslav

Signature · 6 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel