summaryrefslogtreecommitdiff
path: root/libkmod
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2016-08-08 11:42:52 -0300
committerLucas De Marchi <lucas.demarchi@intel.com>2016-08-08 11:42:52 -0300
commit53d3a99cccf08016eff0351884e7e86a658dffd6 (patch)
tree7ec9210a98dc79d535760d38a2d6792898d77f8d /libkmod
parent65a885df5f6f15222b44fd695c5eaca17e837a14 (diff)
downloadkmod-53d3a99cccf08016eff0351884e7e86a658dffd6.tar.gz
kmod-53d3a99cccf08016eff0351884e7e86a658dffd6.tar.bz2
kmod-53d3a99cccf08016eff0351884e7e86a658dffd6.zip
libkmod: fix use of strcpy
We were not checking if there was sufficient space in the buffer.
Diffstat (limited to 'libkmod')
-rw-r--r--libkmod/libkmod-config.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
index 57fbe37..19f56a7 100644
--- a/libkmod/libkmod-config.c
+++ b/libkmod/libkmod-config.c
@@ -844,15 +844,20 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config,
config->ctx = ctx;
for (; list != NULL; list = kmod_list_remove(list)) {
- char fn[PATH_MAX];
+ char buf[PATH_MAX];
+ const char *fn = buf;
struct conf_file *cf = list->data;
int fd;
- if (cf->is_single)
- strcpy(fn, cf->path);
- else
- snprintf(fn, sizeof(fn),"%s/%s", cf->path,
- cf->name);
+ if (cf->is_single) {
+ fn = cf->path;
+ } else if (snprintf(buf, sizeof(buf), "%s/%s",
+ cf->path, cf->name) >= (int)sizeof(buf)) {
+ ERR(ctx, "Error parsing %s/%s: path too long\n",
+ cf->path, cf->name);
+ free(cf);
+ continue;
+ }
fd = open(fn, O_RDONLY|O_CLOEXEC);
DBG(ctx, "parsing file '%s' fd=%d\n", fn, fd);