Messages in this thread Patch in this message | | | From | Erwan Velu <> | Subject | [PATCH 1/2] nvme: Ensure char members of struct nvme_id_ctrl are null-terminated | Date | Tue, 14 Jun 2022 23:09:01 +0200 |
| |
When issueing an identify command, the resulting data structure stored as a nvme_id_ctrl struct, contains a couple of char members.
These char members features: - the serial number (sn) - the model number (mn) - the firmware revision (fr)
As per the current code, nothing enforce these members to be null-terminated which causes issues when manipulating them with regular string manupulation functions.
This commit ensure the three of them are always null-terminated.
Signed-off-by: Erwan Velu <e.velu@criteo.com> --- drivers/nvme/host/core.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 24165daee3c8..0f7e625e8bd0 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1274,6 +1274,13 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id) sizeof(struct nvme_id_ctrl)); if (error) kfree(*id); + else { + /* Ensure that model, serial and firmware fields are always null-terminated */ + (*id)->mn[sizeof((*id)->mn)-1] = 0; + (*id)->sn[sizeof((*id)->sn)-1] = 0; + (*id)->fr[sizeof((*id)->fr)-1] = 0; + } + return error; } -- 2.35.3
| |