From 1dc96732c2431806dc29aad4961e07ca92f53e86 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 28 Sep 2006 15:47:25 +0200 Subject: [PATCH] configuration: avoid endless loop when a key refers to itself remove one warning from tlv_read routine in control.c --- src/conf.c | 21 +++++++++++++++++++-- src/control/control.c | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/conf.c b/src/conf.c index 5c0b3a70..cb87df56 100644 --- a/src/conf.c +++ b/src/conf.c @@ -2404,9 +2404,16 @@ int snd_config_save(snd_config_t *config, snd_output_t *out) #define SND_CONFIG_SEARCH_ALIAS(config, base, key, result, fcn1, fcn2) \ { \ snd_config_t *res = NULL; \ + char *old_key; \ int err, first = 1; \ assert(config && key); \ - do { \ + while (1) { \ + old_key = strdup(key); \ + if (old_key == NULL) { \ + err = -ENOMEM; \ + res = NULL; \ + break; \ + } \ err = first && base ? -EIO : fcn1(config, config, key, &res); \ if (err < 0) { \ if (!base) \ @@ -2415,8 +2422,18 @@ int snd_config_save(snd_config_t *config, snd_output_t *out) if (err < 0) \ break; \ } \ + if (snd_config_get_string(res, &key) < 0) \ + break; \ + if (!first && strcmp(key, old_key) == 0) { \ + SNDERR("key %s refers to itself"); \ + err = -EINVAL; \ + res = NULL; \ + break; \ + } \ + free(old_key); \ first = 0; \ - } while (snd_config_get_string(res, &key) >= 0); \ + } \ + free(old_key); \ if (!res) \ return err; \ if (result) \ diff --git a/src/control/control.c b/src/control/control.c index 4299e772..0a939ff7 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -469,7 +469,7 @@ int snd_ctl_elem_tlv_read(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, tlv[0] = -1; tlv[1] = 0; err = snd_ctl_tlv_do(ctl, 0, id, tlv, tlv_size); - if (err >= 0 && tlv[0] == -1) + if (err >= 0 && tlv[0] == (unsigned int)-1) err = -ENXIO; return err; } -- 2.11.0