Commit e361200b authored by Chen Gang's avatar Chen Gang Committed by Kent Yoder

drivers/char/tpm/tpm_ppi: use strlcpy instead of strncpy

 Ensure that the 'version' string includes a NULL terminator after its
copied out of the acpi table.
Signed-off-by: default avatarChen Gang <gang.chen@asianux.com>
Signed-off-by: default avatarKent Yoder <key@linux.vnet.ibm.com>
parent 2d089f82
...@@ -158,9 +158,9 @@ static ssize_t tpm_store_ppi_request(struct device *dev, ...@@ -158,9 +158,9 @@ static ssize_t tpm_store_ppi_request(struct device *dev,
ACPI_TYPE_STRING); ACPI_TYPE_STRING);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENOMEM; return -ENOMEM;
strncpy(version, strlcpy(version,
((union acpi_object *)output.pointer)->string.pointer, ((union acpi_object *)output.pointer)->string.pointer,
PPI_VERSION_LEN); PPI_VERSION_LEN + 1);
kfree(output.pointer); kfree(output.pointer);
output.length = ACPI_ALLOCATE_BUFFER; output.length = ACPI_ALLOCATE_BUFFER;
output.pointer = NULL; output.pointer = NULL;
...@@ -237,9 +237,9 @@ static ssize_t tpm_show_ppi_transition_action(struct device *dev, ...@@ -237,9 +237,9 @@ static ssize_t tpm_show_ppi_transition_action(struct device *dev,
ACPI_TYPE_STRING); ACPI_TYPE_STRING);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENOMEM; return -ENOMEM;
strncpy(version, strlcpy(version,
((union acpi_object *)output.pointer)->string.pointer, ((union acpi_object *)output.pointer)->string.pointer,
PPI_VERSION_LEN); PPI_VERSION_LEN + 1);
/* /*
* PPI spec defines params[3].type as empty package, but some platforms * PPI spec defines params[3].type as empty package, but some platforms
* (e.g. Capella with PPI 1.0) need integer/string/buffer type, so for * (e.g. Capella with PPI 1.0) need integer/string/buffer type, so for
...@@ -351,7 +351,7 @@ static ssize_t tpm_show_ppi_response(struct device *dev, ...@@ -351,7 +351,7 @@ static ssize_t tpm_show_ppi_response(struct device *dev,
static ssize_t show_ppi_operations(char *buf, u32 start, u32 end) static ssize_t show_ppi_operations(char *buf, u32 start, u32 end)
{ {
char *str = buf; char *str = buf;
char version[PPI_VERSION_LEN]; char version[PPI_VERSION_LEN + 1];
acpi_handle handle; acpi_handle handle;
acpi_status status; acpi_status status;
struct acpi_object_list input; struct acpi_object_list input;
...@@ -381,9 +381,9 @@ static ssize_t show_ppi_operations(char *buf, u32 start, u32 end) ...@@ -381,9 +381,9 @@ static ssize_t show_ppi_operations(char *buf, u32 start, u32 end)
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENOMEM; return -ENOMEM;
strncpy(version, strlcpy(version,
((union acpi_object *)output.pointer)->string.pointer, ((union acpi_object *)output.pointer)->string.pointer,
PPI_VERSION_LEN); PPI_VERSION_LEN + 1);
kfree(output.pointer); kfree(output.pointer);
output.length = ACPI_ALLOCATE_BUFFER; output.length = ACPI_ALLOCATE_BUFFER;
output.pointer = NULL; output.pointer = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment