[alsa-devel] [PATCH v6 1/3] ucm: Assure the user input card name not to exceed max size of card long name
mengdong.lin at linux.intel.com
mengdong.lin at linux.intel.com
Wed Jan 18 04:52:35 CET 2017
From: Mengdong Lin <mengdong.lin at 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 at linux.intel.com>
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
#define ALSA_USE_CASE_DIR ALSA_CONFIG_DIR "/ucm"
#define SEQUENCE_ELEMENT_TYPE_CDEV 1
--
2.7.4
More information about the Alsa-devel
mailing list