diff options
| author | Thomas Weißschuh <thomas@t-8ch.de> | 2023-09-13 00:08:05 +0200 |
|---|---|---|
| committer | Thomas Weißschuh <thomas@t-8ch.de> | 2023-09-13 08:37:02 +0200 |
| commit | c866bbbe7f2603804687b8dd6fc71a3978f7270e (patch) | |
| tree | 5b3ef090173b2f34c37ceaaf7f84e5ccc5a5e8e1 /lib/path.c | |
| parent | c89edac5c300a254dd9be09191702b9e5c8c536f (diff) | |
| download | util-linux-c866bbbe7f2603804687b8dd6fc71a3978f7270e.tar.gz | |
lib/path: remove usage of VLA
Variable-length-arrays are susceptible to security issues, avoid them.
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Diffstat (limited to 'lib/path.c')
| -rw-r--r-- | lib/path.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/path.c b/lib/path.c index 95a6b8b895..9d4d3585b1 100644 --- a/lib/path.c +++ b/lib/path.c @@ -1020,41 +1020,55 @@ static int ul_path_cpuparse(struct path_cxt *pc, cpu_set_t **set, int maxcpus, i { FILE *f; size_t setsize, len = maxcpus * 7; - char buf[len]; + char *buf; int rc; *set = NULL; + buf = malloc(len); + if (!buf) + return -ENOMEM; + f = ul_path_vfopenf(pc, "r" UL_CLOEXECSTR, path, ap); - if (!f) - return -errno; + if (!f) { + rc = -errno; + goto out; + } rc = fgets(buf, len, f) == NULL ? -EIO : 0; fclose(f); if (rc) - return rc; + goto out; len = strlen(buf); if (buf[len - 1] == '\n') buf[len - 1] = '\0'; *set = cpuset_alloc(maxcpus, &setsize, NULL); - if (!*set) - return -ENOMEM; + if (!*set) { + rc = -EINVAL; + goto out; + } if (islist) { if (cpulist_parse(buf, *set, setsize, 0)) { - cpuset_free(*set); - return -EINVAL; + rc = -EINVAL; + goto out; } } else { if (cpumask_parse(buf, *set, setsize)) { - cpuset_free(*set); - return -EINVAL; + rc = -EINVAL; + goto out; } } - return 0; + rc = 0; + +out: + if (rc) + cpuset_free(*set); + free(buf); + return rc; } int ul_path_readf_cpuset(struct path_cxt *pc, cpu_set_t **set, int maxcpus, const char *path, ...) |
