summaryrefslogtreecommitdiffstats
path: root/lib/path.c
diff options
context:
space:
mode:
authorRuediger Meier2017-06-27 20:32:52 +0200
committerRuediger Meier2017-06-27 21:39:35 +0200
commite230ae7b68814a2ea560e5138188a58128e34417 (patch)
tree8eaab2a06c417004a5477ad6cba769639eb72a76 /lib/path.c
parentsetpriv: add --ambient-caps to usage() (diff)
downloadkernel-qcow2-util-linux-e230ae7b68814a2ea560e5138188a58128e34417.tar.gz
kernel-qcow2-util-linux-e230ae7b68814a2ea560e5138188a58128e34417.tar.xz
kernel-qcow2-util-linux-e230ae7b68814a2ea560e5138188a58128e34417.zip
lib/path: fix crash, pathbuf overflow
Before: $ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)" Segmentation fault (core dumped) After: $ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)" lscpu: invalid argument to --sysroot: File name too long Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'lib/path.c')
-rw-r--r--lib/path.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/path.c b/lib/path.c
index 1a623bc6d..eaa6d881c 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -244,12 +244,18 @@ path_read_cpulist(int maxcpus, const char *path, ...)
return set;
}
-void
+int
path_set_prefix(const char *prefix)
{
- prefixlen = strlen(prefix);
- strncpy(pathbuf, prefix, sizeof(pathbuf));
- pathbuf[sizeof(pathbuf) - 1] = '\0';
+ size_t len = strlen(prefix);
+
+ if (len >= sizeof(pathbuf) - 1) {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+ prefixlen = len;
+ strcpy(pathbuf, prefix);
+ return 0;
}
#endif /* HAVE_CPU_SET_T */