configuration: avoid endless loop when a key refers to itself

remove one warning from tlv_read routine in control.c
This commit is contained in:
Jaroslav Kysela 2006-09-28 15:47:25 +02:00
parent 436b003173
commit 1dc96732c2
2 changed files with 20 additions and 3 deletions

View file

@ -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) \ #define SND_CONFIG_SEARCH_ALIAS(config, base, key, result, fcn1, fcn2) \
{ \ { \
snd_config_t *res = NULL; \ snd_config_t *res = NULL; \
char *old_key; \
int err, first = 1; \ int err, first = 1; \
assert(config && key); \ 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); \ err = first && base ? -EIO : fcn1(config, config, key, &res); \
if (err < 0) { \ if (err < 0) { \
if (!base) \ if (!base) \
@ -2415,8 +2422,18 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
if (err < 0) \ if (err < 0) \
break; \ 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; \ first = 0; \
} while (snd_config_get_string(res, &key) >= 0); \ } \
free(old_key); \
if (!res) \ if (!res) \
return err; \ return err; \
if (result) \ if (result) \

View file

@ -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[0] = -1;
tlv[1] = 0; tlv[1] = 0;
err = snd_ctl_tlv_do(ctl, 0, id, tlv, tlv_size); 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; err = -ENXIO;
return err; return err;
} }