diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2023-02-14 20:59:56 +0100 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2023-02-17 00:00:04 +0100 |
commit | 7bc5c8ac3d4c6004de24050fd51d3eaa4732822d (patch) | |
tree | 976917cdb54bf6a3c8ae98c67b8b380645cd8bfd /lib/commands | |
parent | fb930c2165c2b62daf2adc9d97d59f129132e5c3 (diff) | |
download | lvm2-7bc5c8ac3d4c6004de24050fd51d3eaa4732822d.tar.gz |
cov: avoid using strcpy
Coverity is complaining about unchecked strcpy here, which is
irelevant as we preallocate buffer to fit in copied string,
however we could actually reuse these size and use just memcpy().
So lets make some simple conversions.
Diffstat (limited to 'lib/commands')
-rw-r--r-- | lib/commands/toolcontext.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c index b630554a9..4e05f9078 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -1581,7 +1581,7 @@ struct cmd_context *create_config_context(void) if (!(cmd = zalloc(sizeof(*cmd)))) goto_out; - strcpy(cmd->system_dir, DEFAULT_SYS_DIR); + strncpy(cmd->system_dir, DEFAULT_SYS_DIR, sizeof(cmd->system_dir) - 1); if (!_get_env_vars(cmd)) goto_out; @@ -1713,10 +1713,8 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd, /* * Environment variable LVM_SYSTEM_DIR overrides this below. */ - if (system_dir) - strncpy(cmd->system_dir, system_dir, sizeof(cmd->system_dir) - 1); - else - strcpy(cmd->system_dir, DEFAULT_SYS_DIR); + strncpy(cmd->system_dir, (system_dir) ? system_dir : DEFAULT_SYS_DIR, + sizeof(cmd->system_dir) - 1); if (!_get_env_vars(cmd)) goto_out; |