]> git.alsa-project.org Git - alsa-lib.git/commitdiff
configuration: avoid endless loop when a key refers to itself
authorJaroslav Kysela <perex@perex.cz>
Thu, 28 Sep 2006 13:47:25 +0000 (15:47 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 28 Sep 2006 13:47:25 +0000 (15:47 +0200)
remove one warning from tlv_read routine in control.c

src/conf.c
src/control/control.c

index 5c0b3a7090a18eecac10b9f5b980e63c496422a0..cb87df569794735f927db22be071bd284e670643 100644 (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) \
 { \
        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) \
index 4299e772f286b751f9cd604be6bd98ff788129d2..0a939ff71ef8a9f4bb71c75a472d49d8d2e2661a 100644 (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[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;
 }