aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpica
diff options
context:
space:
mode:
authorBob Moore <robert.moore@intel.com>2013-10-28 21:29:21 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-10-30 07:24:21 -0400
commit73424473d0801f7079258897901ba1edc660dbd3 (patch)
treea1a84628fe0799dda1fa12471ff8592bd5fff73d /drivers/acpi/acpica
parentc26f3c908091294e5909f5459b6682e10922c824 (diff)
ACPICA: Add safe versions of common string functions.
This change adds and deploys "safe" versions of strcpy and strcat that ensure that the target buffer does not overflow. These safe functions are only helpful for processing user input and command lines. For most ACPICA code however, the required buffer length is precisely calculated before buffer allocation, so the use of these functions is unnecessary. ACPICA BZ 1043. This change only applies to the ACPICA utilities and the debugger, none of which are not shipped with the kernel yet, so the kernel's behavior remains unchanged after it. References: https://bugs.acpica.org/show_bug.cgi?id=1043 Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/acpica')
-rw-r--r--drivers/acpi/acpica/aclocal.h2
-rw-r--r--drivers/acpi/acpica/acutils.h11
-rw-r--r--drivers/acpi/acpica/utstring.c62
3 files changed, 74 insertions, 1 deletions
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index dafa0f6c5fe8..53ed1a8ba4f0 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -1072,7 +1072,7 @@ struct acpi_db_method_info {
1072 char *name; 1072 char *name;
1073 u32 flags; 1073 u32 flags;
1074 u32 num_loops; 1074 u32 num_loops;
1075 char pathname[128]; 1075 char pathname[ACPI_DB_LINE_BUFFER_SIZE];
1076 char **args; 1076 char **args;
1077 acpi_object_type *types; 1077 acpi_object_type *types;
1078 1078
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index d5a62a6182bb..4f25e8f0cd5f 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -628,6 +628,17 @@ u8 acpi_ut_valid_acpi_char(char character, u32 position);
628 628
629void acpi_ut_repair_name(char *name); 629void acpi_ut_repair_name(char *name);
630 630
631#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
632u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source);
633
634u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source);
635
636u8
637acpi_ut_safe_strncat(char *dest,
638 acpi_size dest_size,
639 char *source, acpi_size max_transfer_length);
640#endif
641
631/* 642/*
632 * utmutex - mutex support 643 * utmutex - mutex support
633 */ 644 */
diff --git a/drivers/acpi/acpica/utstring.c b/drivers/acpi/acpica/utstring.c
index cb1e9cc32d5f..5ef41ffcf575 100644
--- a/drivers/acpi/acpica/utstring.c
+++ b/drivers/acpi/acpica/utstring.c
@@ -584,3 +584,65 @@ void ut_convert_backslashes(char *pathname)
584 } 584 }
585} 585}
586#endif 586#endif
587
588#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
589/*******************************************************************************
590 *
591 * FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat
592 *
593 * PARAMETERS: Adds a "DestSize" parameter to each of the standard string
594 * functions. This is the size of the Destination buffer.
595 *
596 * RETURN: TRUE if the operation would overflow the destination buffer.
597 *
598 * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that
599 * the result of the operation will not overflow the output string
600 * buffer.
601 *
602 * NOTE: These functions are typically only helpful for processing
603 * user input and command lines. For most ACPICA code, the
604 * required buffer length is precisely calculated before buffer
605 * allocation, so the use of these functions is unnecessary.
606 *
607 ******************************************************************************/
608
609u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source)
610{
611
612 if (ACPI_STRLEN(source) >= dest_size) {
613 return (TRUE);
614 }
615
616 ACPI_STRCPY(dest, source);
617 return (FALSE);
618}
619
620u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source)
621{
622
623 if ((ACPI_STRLEN(dest) + ACPI_STRLEN(source)) >= dest_size) {
624 return (TRUE);
625 }
626
627 ACPI_STRCAT(dest, source);
628 return (FALSE);
629}
630
631u8
632acpi_ut_safe_strncat(char *dest,
633 acpi_size dest_size,
634 char *source, acpi_size max_transfer_length)
635{
636 acpi_size actual_transfer_length;
637
638 actual_transfer_length =
639 ACPI_MIN(max_transfer_length, ACPI_STRLEN(source));
640
641 if ((ACPI_STRLEN(dest) + actual_transfer_length) >= dest_size) {
642 return (TRUE);
643 }
644
645 ACPI_STRNCAT(dest, source, max_transfer_length);
646 return (FALSE);
647}
648#endif