topology: do not call strtol directly

Introduce safe_strtol_base() function and redirects all
strtol calls there. Also, improve error and value handling
in callers.

BugLink: https://github.com/alsa-project/alsa-lib/issues/187
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2021-11-02 10:43:27 +01:00
parent f547b2e35f
commit 5fab157a59
3 changed files with 40 additions and 19 deletions

View file

@ -414,12 +414,8 @@ static int write_hex(char *buf, char *str, int width)
void *p = &val;
errno = 0;
val = strtol(str, NULL, 16);
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
|| (errno != 0 && val == 0)) {
if (safe_strtol_base(str, &val, 16) < 0)
return -EINVAL;
}
switch (width) {
case 1: