Skip to content

Commit ee68d47

Browse files
acpibobrafaeljw
authored andcommitted
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: acpica/acpica@64ad9c69 Signed-off-by: Bob Moore <[email protected]> Signed-off-by: Erik Schmauss <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 2cb0ba7 commit ee68d47

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

drivers/acpi/acpica/acutils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,11 @@ void ut_convert_backslashes(char *pathname);
638638

639639
void acpi_ut_repair_name(char *name);
640640

641-
#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
641+
#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) || defined (ACPI_DEBUG_OUTPUT)
642642
u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source);
643643

644+
void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size);
645+
644646
u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source);
645647

646648
u8

drivers/acpi/acpica/dbfileio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void acpi_db_open_debug_file(char *name)
9999
}
100100

101101
acpi_os_printf("Debug output file %s opened\n", name);
102-
strncpy(acpi_gbl_db_debug_filename, name,
103-
sizeof(acpi_gbl_db_debug_filename));
102+
acpi_ut_safe_strncpy(acpi_gbl_db_debug_filename, name,
103+
sizeof(acpi_gbl_db_debug_filename));
104104
acpi_gbl_db_output_to_file = TRUE;
105105
}
106106
#endif

drivers/acpi/acpica/psutils.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ void acpi_ps_init_op(union acpi_parse_object *op, u16 opcode)
9494
op->common.descriptor_type = ACPI_DESC_TYPE_PARSER;
9595
op->common.aml_opcode = opcode;
9696

97-
ACPI_DISASM_ONLY_MEMBERS(strncpy(op->common.aml_op_name,
98-
(acpi_ps_get_opcode_info(opcode))->
99-
name, sizeof(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
99+
(opcode))->name,
100+
sizeof(op->common.
101+
aml_op_name)));
100102
}
101103

102104
/*******************************************************************************

drivers/acpi/acpica/utnonansi.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int acpi_ut_stricmp(char *string1, char *string2)
140140
return (c1 - c2);
141141
}
142142

143-
#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
143+
#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) || defined (ACPI_DEBUG_OUTPUT)
144144
/*******************************************************************************
145145
*
146146
* FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat
@@ -199,4 +199,13 @@ acpi_ut_safe_strncat(char *dest,
199199
strncat(dest, source, max_transfer_length);
200200
return (FALSE);
201201
}
202+
203+
void 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+
202211
#endif

drivers/acpi/acpica/uttrack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation,
402402
allocation->component = component;
403403
allocation->line = line;
404404

405-
strncpy(allocation->module, module, ACPI_MAX_MODULE_NAME);
406-
allocation->module[ACPI_MAX_MODULE_NAME - 1] = 0;
405+
acpi_ut_safe_strncpy(allocation->module, (char *)module,
406+
ACPI_MAX_MODULE_NAME);
407407

408408
if (!element) {
409409

0 commit comments

Comments
 (0)