aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCaleb Connolly <caleb.connolly@linaro.org>2021-11-02 18:56:21 +0000
committerCaleb Connolly <caleb.connolly@linaro.org>2021-11-02 21:51:32 +0000
commitb49414ea5da073042aab753a4fd9fd05fa5bb8d5 (patch)
tree6f7b782f0dfc64b5c5b0cf37c7983988015fb19d /src
parent9109c94f269102785c606bd6c211b52fbbcd822d (diff)
mixer: fix index underflow when index=0
In mixer_get_ctl_by_name_and_index(), the post-fix decrement means that the index will be decremented after the comparison, but before the return, leading to an unsigned integer underflow. This causes a crash on platforms with -fsanitize=integer enabled. Fix this by avoiding decrementing index until after the return. Change-Id: I25a17ced4185bdebd500285bd30b342b16b4ac12
Diffstat (limited to 'src')
-rw-r--r--src/mixer.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/mixer.c b/src/mixer.c
index 5581e5d..b4d96fd 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -732,9 +732,13 @@ struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer,
ctl = grp->ctl;
for (n = 0; n < grp->count; n++)
- if (!strcmp(name, (char*) ctl[n].info.id.name))
- if (index-- == 0)
+ if (!strcmp(name, (char*) ctl[n].info.id.name)) {
+ if (index == 0) {
return ctl + n;
+ } else {
+ index--;
+ }
+ }
}
#ifdef TINYALSA_USES_PLUGINS
@@ -743,9 +747,13 @@ struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer,
ctl = grp->ctl;
for (n = 0; n < grp->count; n++)
- if (!strcmp(name, (char*) ctl[n].info.id.name))
- if (index-- == 0)
+ if (!strcmp(name, (char*) ctl[n].info.id.name)) {
+ if (index == 0) {
return ctl + n;
+ } else {
+ index--;
+ }
+ }
}
#endif
return NULL;