diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index fadcaca34..e6f4ec886 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -1380,6 +1380,7 @@ int dev_cache_add_dir(const char *path) { struct dir_list *dl; struct stat st; + size_t len; if (stat(path, &st)) { log_warn("Ignoring %s: %s.", path, strerror(errno)); @@ -1392,12 +1393,13 @@ int dev_cache_add_dir(const char *path) return 1; } - if (!(dl = _zalloc(sizeof(*dl) + strlen(path) + 1))) { + len = strlen(path); + if (!(dl = _zalloc(sizeof(*dl) + len + 1))) { log_error("dir_list allocation failed"); return 0; } - strcpy(dl->dir, path); + memcpy(dl->dir, path, len + 1); dm_list_add(&_cache.dirs, &dl->list); return 1; } diff --git a/lib/label/label.c b/lib/label/label.c index 38b5cf799..500a43364 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -55,15 +55,15 @@ static struct labeller_i *_alloc_li(const char *name, struct labeller *l) struct labeller_i *li; size_t len; - len = sizeof(*li) + strlen(name) + 1; + len = strlen(name); - if (!(li = malloc(len))) { + if (!(li = malloc(sizeof(*li) + len + 1))) { log_error("Couldn't allocate memory for labeller list object."); return NULL; } li->l = l; - strcpy(li->name, name); + memcpy(li->name, name, len + 1); return li; } diff --git a/libdaemon/client/config-util.c b/libdaemon/client/config-util.c index 3f27f3149..b0813f176 100644 --- a/libdaemon/client/config-util.c +++ b/libdaemon/client/config-util.c @@ -383,7 +383,7 @@ int buffer_append(struct buffer *buf, const char *string) !buffer_realloc(buf, len + 1)) return 0; - strcpy(buf->mem + buf->used, string); + memcpy(buf->mem + buf->used, string, len + 1); buf->used += len; return 1; }