summaryrefslogtreecommitdiffstats
path: root/alsa-binding/Alsa-SetGet.c
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-06-19 15:57:07 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2018-06-19 15:58:59 +0200
commitd732feea86cf2f9c35c4529769978e5ab29cd881 (patch)
treedb8e29cff77a56cdc4d1bda91762702e70fc0905 /alsa-binding/Alsa-SetGet.c
parent66bf020290892b19fb61a01f260e47cd5ff35f3e (diff)
Fixed crash when 'set' request is based on numidseel_5.1.0eel/5.1.05.1.0eel
When numids are given, the 'tag' field is not initialized to NULL, and leads to a crash on strcasecmp. Change-Id: I23a1552bba565259280140a5e099be10613ab1bc Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'alsa-binding/Alsa-SetGet.c')
-rw-r--r--alsa-binding/Alsa-SetGet.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/alsa-binding/Alsa-SetGet.c b/alsa-binding/Alsa-SetGet.c
index 9ed316c..a755b02 100644
--- a/alsa-binding/Alsa-SetGet.c
+++ b/alsa-binding/Alsa-SetGet.c
@@ -42,6 +42,7 @@ PUBLIC void NumidsListParse(ActionSetGetT action, queryValuesT *queryValues, ctl
for (int idx = 0; idx < queryValues->count; idx++) {
json_object *jId, *valuesJ;
ctlRequest[idx].used = 0;
+ ctlRequest[idx].tag = NULL;
ctlRequest[idx].valuesJ = NULL;
// when only one NUMID is provided it might not be encapsulated in a JSON array
@@ -101,7 +102,7 @@ PUBLIC void NumidsListParse(ActionSetGetT action, queryValuesT *queryValues, ctl
AFB_NOTICE("Invalid Json=%s missing 'val'", json_object_get_string(ctlRequest[idx].jToken));
ctlRequest[idx].used = -1;
} else
- ctlRequest[idx].valuesJ = valuesJ;
+ ctlRequest[idx].valuesJ = valuesJ;
}
}
break;
@@ -720,7 +721,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req request) {
queryJ = alsaCheckQuery(request, &queryValues);
if (!queryJ) goto OnErrorExit;
- // Prase Numids + optional values
+ // Phrase Numids + optional values
done = json_object_object_get_ex(queryJ, "ctl", &numidsJ);
if (!done) queryValues.count = 0;
else {
@@ -769,6 +770,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req request) {
ctlCount = snd_ctl_elem_list_get_used(ctlList);
if (queryValues.count == 0) {
ctlRequest = alloca(sizeof (ctlRequestT)*(ctlCount));
+ ctlRequest->tag = NULL;
} else {
ctlRequest = alloca(sizeof (ctlRequestT)*(queryValues.count));
NumidsListParse(action, &queryValues, ctlRequest);
@@ -793,9 +795,14 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req request) {
AFB_NOTICE("snd_ctl_elem_list_get_numid index=%d fail", ctlIndex);
continue;
}
+
// check if current control was requested in query numids list
for (jdx = 0; jdx < queryValues.count; jdx++) {
- if (numid == ctlRequest[jdx].numId || ! strcasecmp(tag, ctlRequest[jdx].tag)) {
+
+ if (numid == ctlRequest[jdx].numId ||
+ (ctlRequest[jdx].tag != NULL &&
+ !strcasecmp(tag, ctlRequest[jdx].tag))
+ ) {
ctlRequest[jdx].numId = numid;
selected = 1;
break;