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.
This commit is contained in:
Clemens Ladisch 2006-09-18 17:57:58 +02:00
parent a7bc1dd80c
commit 0211bc3b68
3 changed files with 10 additions and 18 deletions

View 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;

View 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) {

View 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);