summaryrefslogtreecommitdiff
path: root/source/components/utilities/utstring.c
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2013-10-17 00:06:42 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2013-10-17 00:06:42 +0000
commita6028f7332dbf61541a4482e402bf346dad53118 (patch)
tree3908357b831dbb78c746f73c443b4d7ba5e966f9 /source/components/utilities/utstring.c
parent59ce063597ddbda74269a45aba8187dece2fe00a (diff)
Notes
Diffstat (limited to 'source/components/utilities/utstring.c')
-rw-r--r--source/components/utilities/utstring.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/source/components/utilities/utstring.c b/source/components/utilities/utstring.c
index 97987003fe8c..282869c5416d 100644
--- a/source/components/utilities/utstring.c
+++ b/source/components/utilities/utstring.c
@@ -685,3 +685,78 @@ UtConvertBackslashes (
}
}
#endif
+
+#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtSafeStrcpy, AcpiUtSafeStrcat, AcpiUtSafeStrncat
+ *
+ * PARAMETERS: Adds a "DestSize" parameter to each of the standard string
+ * functions. This is the size of the Destination buffer.
+ *
+ * RETURN: TRUE if the operation would overflow the destination buffer.
+ *
+ * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that
+ * the result of the operation will not overflow the output string
+ * buffer.
+ *
+ * NOTE: These functions are typically only helpful for processing
+ * user input and command lines. For most ACPICA code, the
+ * required buffer length is precisely calculated before buffer
+ * allocation, so the use of these functions is unnecessary.
+ *
+ ******************************************************************************/
+
+BOOLEAN
+AcpiUtSafeStrcpy (
+ char *Dest,
+ ACPI_SIZE DestSize,
+ char *Source)
+{
+
+ if (ACPI_STRLEN (Source) >= DestSize)
+ {
+ return (TRUE);
+ }
+
+ ACPI_STRCPY (Dest, Source);
+ return (FALSE);
+}
+
+BOOLEAN
+AcpiUtSafeStrcat (
+ char *Dest,
+ ACPI_SIZE DestSize,
+ char *Source)
+{
+
+ if ((ACPI_STRLEN (Dest) + ACPI_STRLEN (Source)) >= DestSize)
+ {
+ return (TRUE);
+ }
+
+ ACPI_STRCAT (Dest, Source);
+ return (FALSE);
+}
+
+BOOLEAN
+AcpiUtSafeStrncat (
+ char *Dest,
+ ACPI_SIZE DestSize,
+ char *Source,
+ ACPI_SIZE MaxTransferLength)
+{
+ ACPI_SIZE ActualTransferLength;
+
+
+ ActualTransferLength = ACPI_MIN (MaxTransferLength, ACPI_STRLEN (Source));
+
+ if ((ACPI_STRLEN (Dest) + ActualTransferLength) >= DestSize)
+ {
+ return (TRUE);
+ }
+
+ ACPI_STRNCAT (Dest, Source, MaxTransferLength);
+ return (FALSE);
+}
+#endif