1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

coverity: ensure 0 end string

Use dm_strncpy() to enusure string ends with '\0'.
In case uuid does not fit, report error.
This commit is contained in:
Zdenek Kabelac 2018-03-29 19:07:31 +02:00
parent 037c234eaa
commit fa5ba7e42d
2 changed files with 8 additions and 4 deletions

View File

@ -1631,7 +1631,7 @@ int create_cluster_cpg(char *uuid, uint64_t luid)
size = ((strlen(uuid) + 1) > CPG_MAX_NAME_LENGTH) ? size = ((strlen(uuid) + 1) > CPG_MAX_NAME_LENGTH) ?
CPG_MAX_NAME_LENGTH : (strlen(uuid) + 1); CPG_MAX_NAME_LENGTH : (strlen(uuid) + 1);
strncpy(new->name.value, uuid, size); (void) dm_strncpy(new->name.value, uuid, size);
new->name.length = (uint32_t)size; new->name.length = (uint32_t)size;
new->luid = luid; new->luid = luid;

View File

@ -451,15 +451,19 @@ static int _clog_ctr(char *uuid, uint64_t luid,
lc->skip_bit_warning = region_count; lc->skip_bit_warning = region_count;
lc->disk_fd = -1; lc->disk_fd = -1;
lc->log_dev_failed = 0; lc->log_dev_failed = 0;
strncpy(lc->uuid, uuid, DM_UUID_LEN); if (!dm_strncpy(lc->uuid, uuid, DM_UUID_LEN)) {
LOG_ERROR("Cannot use too long UUID %s.", uuid);
r = -EINVAL;
goto fail;
}
lc->luid = luid; lc->luid = luid;
if (get_log(lc->uuid, lc->luid) || if (get_log(lc->uuid, lc->luid) ||
get_pending_log(lc->uuid, lc->luid)) { get_pending_log(lc->uuid, lc->luid)) {
LOG_ERROR("[%s/%" PRIu64 "u] Log already exists, unable to create.", LOG_ERROR("[%s/%" PRIu64 "u] Log already exists, unable to create.",
SHORT_UUID(lc->uuid), lc->luid); SHORT_UUID(lc->uuid), lc->luid);
dm_free(lc); r = -EINVAL;
return -EINVAL; goto fail;
} }
dm_list_init(&lc->mark_list); dm_list_init(&lc->mark_list);