[v6,1/3] ucm: Assure the user input card name not to exceed max size of card long name
diff mbox

Message ID d8494768e045903098472b9ccf7de215eb88fe21.1484710888.git.mengdong.lin@linux.intel.com
State New
Headers show

Commit Message

mengdong.lin@linux.intel.com Jan. 18, 2017, 3:52 a.m. UTC
From: Mengdong Lin <mengdong.lin@linux.intel.com>

Users can load a card's UCM configuration file by giving the card short
name or long name, which should not exceed the maximum card long name
defined by the kernel. The kernel uses an 80-character buffer to store
the card long name.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>

diff mbox

diff --git a/src/ucm/parser.c b/src/ucm/parser.c
index c98373a..3b42e31 100644
--- a/src/ucm/parser.c
+++ b/src/ucm/parser.c
@@ -1334,6 +1334,12 @@  static int load_master_config(const char *card_name, snd_config_t **cfg)
 	char *env = getenv(ALSA_CONFIG_UCM_VAR);
 	int err;
+	if (strnlen(card_name, MAX_CARD_LONG_NAME) == MAX_CARD_LONG_NAME) {
+		uc_error("error: invalid card name %s (at most %d chars)\n",
+			 card_name, MAX_CARD_LONG_NAME - 1);
+		return -EINVAL;
+	}
 	snprintf(filename, sizeof(filename)-1,
 		"%s/%s/%s.conf", env ? env : ALSA_USE_CASE_DIR,
 		card_name, card_name);
diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h
index 6d3302f..e41aafa 100644
--- a/src/ucm/ucm_local.h
+++ b/src/ucm/ucm_local.h
@@ -41,6 +41,7 @@ 
 #include "use-case.h"
 #define MAX_FILE		256
+#define MAX_CARD_LONG_NAME	80