From 0211bc3b6875af9c076517070f0466d257adce51 Mon Sep 17 00:00:00 2001 From: Clemens Ladisch Date: Mon, 18 Sep 2006 17:57:58 +0200 Subject: [PATCH] fix parsing of non-decimal integers in configuration files 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 | 2 +- src/pcm/pcm_direct.c | 13 +++++-------- src/pcm/pcm_file.c | 13 ++++--------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/conf.c b/src/conf.c index 5788773a..5c0b3a70 100644 --- a/src/conf.c +++ b/src/conf.c @@ -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; diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index bfa2d3e3..05750951 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -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) { diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index 77fac2b4..b75eda71 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -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); -- 2.47.1