]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: fix use of strcpy
authorLucas De Marchi <lucas.demarchi@intel.com>
Mon, 8 Aug 2016 14:42:52 +0000 (11:42 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 8 Aug 2016 14:42:52 +0000 (11:42 -0300)
We were not checking if there was sufficient space in the buffer.

libkmod/libkmod-config.c

index 57fbe37815612ecc9538984527abc0d84b5dd10f..19f56a712b729d77d657196bc87096001bf2a201 100644 (file)
@@ -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);