]> git.alsa-project.org Git - alsa-lib.git/commitdiff
fix parsing of non-decimal integers in configuration files
authorClemens Ladisch <clemens@ladisch.de>
Mon, 18 Sep 2006 15:57:58 +0000 (17:57 +0200)
committerClemens Ladisch <clemens@ladisch.de>
Mon, 18 Sep 2006 15:57:58 +0000 (17:57 +0200)
safe_strtoll() now accepts numbers in any base. It formerly assumed that
its input was a decimal number, which had the consequence that
hexadecimal or octal numbers would be parsed as strings when occurring
outside of parameter lists.

This obsoletes some workarounds in the file permission parsing code that
relied on this bug.

src/conf.c
src/pcm/pcm_direct.c
src/pcm/pcm_file.c

index 5788773ab0f52e0831e1a8e205932fb7e54c5125..5c0b3a7090a18eecac10b9f5b980e63c496422a0 100644 (file)
@@ -470,7 +470,7 @@ static int safe_strtoll(const char *str, long long *val)
        if (!*str)
                return -EINVAL;
        errno = 0;
-       if (sscanf(str, "%Ld%n", &v, &endidx) < 1)
+       if (sscanf(str, "%Li%n", &v, &endidx) < 1)
                return -EINVAL;
        if (str[endidx])
                return -EINVAL;
index bfa2d3e389d09aa581c4bbef91060cbece23bb73..057509512370aa564aae52ccdd94e6556a822b50 100644 (file)
@@ -1555,20 +1555,17 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf,
                        continue;
                }
                if (strcmp(id, "ipc_perm") == 0) {
-                       char *perm;
-                       char *endp;
-                       err = snd_config_get_ascii(n, &perm);
+                       long perm;
+                       err = snd_config_get_integer(n, &perm);
                        if (err < 0) {
-                               SNDERR("The field ipc_perm must be a valid file permission");
+                               SNDERR("Invalid type for %s", id);
                                return err;
                        }
-                       if (isdigit(*perm) == 0) {
+                       if ((perm & ~0777) != 0) {
                                SNDERR("The field ipc_perm must be a valid file permission");
-                               free(perm);
                                return -EINVAL;
                        }
-                       rec->ipc_perm = strtol(perm, &endp, 8);
-                       free(perm);
+                       rec->ipc_perm = perm;
                        continue;
                }
                if (strcmp(id, "ipc_gid") == 0) {
index 77fac2b48b4aa26d23ac3d7a4d4f4f605f051cf0..b75eda7117f88cf7909a73f19aee1ee1a3bebf95 100644 (file)
@@ -535,7 +535,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
        const char *fname = NULL, *ifname = NULL;
        const char *format = NULL;
        long fd = -1, ifd = -1;
-       int perm = 0600;
+       long perm = 0600;
        snd_config_for_each(i, next, conf) {
                snd_config_t *n = snd_config_iterator_entry(i);
                const char *id;
@@ -578,20 +578,15 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
                        continue;
                }
                if (strcmp(id, "perm") == 0) {
-                       char *str;
-                       char *endp;
-                       err = snd_config_get_ascii(n, &str);
+                       err = snd_config_get_integer(n, &perm);
                        if (err < 0) {
-                               SNDERR("The field perm must be a valid file permission");
+                               SNDERR("Invalid type for %s", id);
                                return err;
                        }
-                       if (isdigit(*str) == 0) {
+                       if ((perm & ~0777) != 0) {
                                SNDERR("The field perm must be a valid file permission");
-                               free(str);
                                return -EINVAL;
                        }
-                       perm = strtol(str, &endp, 8);
-                       free(str);
                        continue;
                }
                SNDERR("Unknown field %s", id);