diff options
Diffstat (limited to 'source/components/utilities/utstring.c')
| -rw-r--r-- | source/components/utilities/utstring.c | 75 | 
1 files changed, 75 insertions, 0 deletions
diff --git a/source/components/utilities/utstring.c b/source/components/utilities/utstring.c index 97987003fe8c5..282869c5416dc 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  | 
