Skip to content

Commit

Permalink
ucmd: module: dm: don't write garbage keys
Browse files Browse the repository at this point in the history
If SID fails to get the sysfs dm sysfs values, likely because the
device has been removed from sysfs, fail instead of using uninitialized
memory for the key.
  • Loading branch information
bmarzins authored and prajnoha committed Sep 27, 2023
1 parent bcb5663 commit 9d90234
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/modules/ucmd/type/dm/dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,18 @@ static int _dm_ident(struct module *module, struct sid_ucmd_ctx *ucmd_ctx)
log_debug(DM_ID, "ident");

snprintf(path, sizeof(path), "%s%s/dm/uuid", SYSTEM_SYSFS_PATH, sid_ucmd_event_get_dev_path(ucmd_ctx));
sid_util_sysfs_get_value(path, uuid, sizeof(uuid));
if (sid_util_sysfs_get_value(path, uuid, sizeof(uuid)) < 0) {
log_error(DM_ID, "Failed to get DM uuid.");
return -1;
}
sid_ucmd_dev_add_alias(module, ucmd_ctx, "uuid", uuid);
sid_ucmd_set_kv(module, ucmd_ctx, KV_NS_DEVMOD, "uuid", uuid, strlen(uuid) + 1, KV_SYNC | KV_SUB_RD);

snprintf(path, sizeof(path), "%s%s/dm/name", SYSTEM_SYSFS_PATH, sid_ucmd_event_get_dev_path(ucmd_ctx));
sid_util_sysfs_get_value(path, name, sizeof(name));
if (sid_util_sysfs_get_value(path, name, sizeof(name)) < 0) {
log_error(DM_ID, "Failed to get DM name.");
return -1;
}
sid_ucmd_dev_add_alias(module, ucmd_ctx, "name", name);
sid_ucmd_set_kv(module, ucmd_ctx, KV_NS_DEVMOD, "name", name, strlen(name) + 1, KV_SYNC | KV_SUB_RD);

Expand Down

0 comments on commit 9d90234

Please sign in to comment.