From 9d4f9defc31f0459f91979909a0c94bbb87af9c0 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 21 Apr 2016 20:19:53 +0200 Subject: [PATCH] cleanup: simplify code dm_strncpy() also check the size fits. --- lib/locking/file_locking.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c index a8d041ad3..230303b47 100644 --- a/lib/locking/file_locking.c +++ b/lib/locking/file_locking.c @@ -148,13 +148,11 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd, /* Get lockfile directory from config file */ locking_dir = find_config_tree_str(cmd, global_locking_dir_CFG, NULL); - if (strlen(locking_dir) >= sizeof(_lock_dir)) { + if (!dm_strncpy(_lock_dir, locking_dir, sizeof(_lock_dir))) { log_error("Path for locking_dir %s is invalid.", locking_dir); return 0; } - strcpy(_lock_dir, locking_dir); - (void) dm_prepare_selinux_context(_lock_dir, S_IFDIR); r = dm_create_dir(_lock_dir); (void) dm_prepare_selinux_context(NULL, 0);