aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Moore <robert.moore@intel.com>2018-01-04 16:41:27 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2018-01-04 19:33:22 -0500
commitee68d4773ed36e3f79860bbcad0a4ddd8d58f393 (patch)
tree5dd69e007decde8a5ca37b22a59f9b21a293333a
parent2cb0ba70fbbf36f34c2c31fabe19a267ac4a14a3 (diff)
ACPICA: Create and deploy safe version of strncpy
ACPICA commit 64ad9c69a1bd534a466e060a33c0bbf5fc9e189c acpi_ut_safe_strncpy - copy and terminate string. Strncpy is not guaranteed to terminate the copied string if the input is longer than the length of the target. No functional change. Link: https://github.com/acpica/acpica/commit/64ad9c69 Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Erik Schmauss <erik.schmauss@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/acpica/acutils.h4
-rw-r--r--drivers/acpi/acpica/dbfileio.c4
-rw-r--r--drivers/acpi/acpica/psutils.c8
-rw-r--r--drivers/acpi/acpica/utnonansi.c11
-rw-r--r--drivers/acpi/acpica/uttrack.c4
5 files changed, 22 insertions, 9 deletions
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 8bb46d8623ca..b6b29d717824 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -638,9 +638,11 @@ void ut_convert_backslashes(char *pathname);
638 638
639void acpi_ut_repair_name(char *name); 639void acpi_ut_repair_name(char *name);
640 640
641#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) 641#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) || defined (ACPI_DEBUG_OUTPUT)
642u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source); 642u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source);
643 643
644void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size);
645
644u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source); 646u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source);
645 647
646u8 648u8
diff --git a/drivers/acpi/acpica/dbfileio.c b/drivers/acpi/acpica/dbfileio.c
index 4d81ea291d93..cf9607945704 100644
--- a/drivers/acpi/acpica/dbfileio.c
+++ b/drivers/acpi/acpica/dbfileio.c
@@ -99,8 +99,8 @@ void acpi_db_open_debug_file(char *name)
99 } 99 }
100 100
101 acpi_os_printf("Debug output file %s opened\n", name); 101 acpi_os_printf("Debug output file %s opened\n", name);
102 strncpy(acpi_gbl_db_debug_filename, name, 102 acpi_ut_safe_strncpy(acpi_gbl_db_debug_filename, name,
103 sizeof(acpi_gbl_db_debug_filename)); 103 sizeof(acpi_gbl_db_debug_filename));
104 acpi_gbl_db_output_to_file = TRUE; 104 acpi_gbl_db_output_to_file = TRUE;
105} 105}
106#endif 106#endif
diff --git a/drivers/acpi/acpica/psutils.c b/drivers/acpi/acpica/psutils.c
index e15b636b1d4b..8bd7d01039cc 100644
--- a/drivers/acpi/acpica/psutils.c
+++ b/drivers/acpi/acpica/psutils.c
@@ -94,9 +94,11 @@ void acpi_ps_init_op(union acpi_parse_object *op, u16 opcode)
94 op->common.descriptor_type = ACPI_DESC_TYPE_PARSER; 94 op->common.descriptor_type = ACPI_DESC_TYPE_PARSER;
95 op->common.aml_opcode = opcode; 95 op->common.aml_opcode = opcode;
96 96
97 ACPI_DISASM_ONLY_MEMBERS(strncpy(op->common.aml_op_name, 97 ACPI_DISASM_ONLY_MEMBERS(acpi_ut_safe_strncpy(op->common.aml_op_name,
98 (acpi_ps_get_opcode_info(opcode))-> 98 (acpi_ps_get_opcode_info
99 name, sizeof(op->common.aml_op_name))); 99 (opcode))->name,
100 sizeof(op->common.
101 aml_op_name)));
100} 102}
101 103
102/******************************************************************************* 104/*******************************************************************************
diff --git a/drivers/acpi/acpica/utnonansi.c b/drivers/acpi/acpica/utnonansi.c
index 792664982ea3..33a0970646df 100644
--- a/drivers/acpi/acpica/utnonansi.c
+++ b/drivers/acpi/acpica/utnonansi.c
@@ -140,7 +140,7 @@ int acpi_ut_stricmp(char *string1, char *string2)
140 return (c1 - c2); 140 return (c1 - c2);
141} 141}
142 142
143#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) 143#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) || defined (ACPI_DEBUG_OUTPUT)
144/******************************************************************************* 144/*******************************************************************************
145 * 145 *
146 * FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat 146 * FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat
@@ -199,4 +199,13 @@ acpi_ut_safe_strncat(char *dest,
199 strncat(dest, source, max_transfer_length); 199 strncat(dest, source, max_transfer_length);
200 return (FALSE); 200 return (FALSE);
201} 201}
202
203void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size)
204{
205 /* Always terminate destination string */
206
207 strncpy(dest, source, dest_size);
208 dest[dest_size - 1] = 0;
209}
210
202#endif 211#endif
diff --git a/drivers/acpi/acpica/uttrack.c b/drivers/acpi/acpica/uttrack.c
index 28a302eb2015..633b4e2c669f 100644
--- a/drivers/acpi/acpica/uttrack.c
+++ b/drivers/acpi/acpica/uttrack.c
@@ -402,8 +402,8 @@ acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation,
402 allocation->component = component; 402 allocation->component = component;
403 allocation->line = line; 403 allocation->line = line;
404 404
405 strncpy(allocation->module, module, ACPI_MAX_MODULE_NAME); 405 acpi_ut_safe_strncpy(allocation->module, (char *)module,
406 allocation->module[ACPI_MAX_MODULE_NAME - 1] = 0; 406 ACPI_MAX_MODULE_NAME);
407 407
408 if (!element) { 408 if (!element) {
409 409