MdePkg/Library/BaseLib/SafeString.c File Reference


Defines

#define RSIZE_MAX   (PcdGet32 (PcdMaximumUnicodeStringLength))
#define ASCII_RSIZE_MAX   (PcdGet32 (PcdMaximumAsciiStringLength))
#define SAFE_STRING_CONSTRAINT_CHECK(Expression, Status)

Functions

BOOLEAN InternalSafeStringIsOverlap (IN VOID *Base1, IN UINTN Size1, IN VOID *Base2, IN UINTN Size2)
BOOLEAN InternalSafeStringNoStrOverlap (IN CHAR16 *Str1, IN UINTN Size1, IN CHAR16 *Str2, IN UINTN Size2)
BOOLEAN InternalSafeStringNoAsciiStrOverlap (IN CHAR8 *Str1, IN UINTN Size1, IN CHAR8 *Str2, IN UINTN Size2)
UINTN EFIAPI StrnLenS (IN CONST CHAR16 *String, IN UINTN MaxSize)
RETURN_STATUS EFIAPI StrCpyS (OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
RETURN_STATUS EFIAPI StrnCpyS (OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
RETURN_STATUS EFIAPI StrCatS (IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
RETURN_STATUS EFIAPI StrnCatS (IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
UINTN EFIAPI AsciiStrnLenS (IN CONST CHAR8 *String, IN UINTN MaxSize)
RETURN_STATUS EFIAPI AsciiStrCpyS (OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
RETURN_STATUS EFIAPI AsciiStrnCpyS (OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
RETURN_STATUS EFIAPI AsciiStrCatS (IN OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
RETURN_STATUS EFIAPI AsciiStrnCatS (IN OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)

Detailed Description

Safe String functions.

Copyright (c) 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php.

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.


Define Documentation

#define ASCII_RSIZE_MAX   (PcdGet32 (PcdMaximumAsciiStringLength))

#define RSIZE_MAX   (PcdGet32 (PcdMaximumUnicodeStringLength))

Referenced by StrCatS(), StrCpyS(), StrnCatS(), and StrnCpyS().

#define SAFE_STRING_CONSTRAINT_CHECK ( Expression,
Status   ) 

Value:

do { \
    ASSERT (Expression); \
    if (!(Expression)) { \
      return Status; \
    } \
  } while (FALSE)

Referenced by AsciiStrCatS(), AsciiStrCpyS(), AsciiStrnCatS(), AsciiStrnCpyS(), StrCatS(), StrCpyS(), StrnCatS(), and StrnCpyS().


Function Documentation

RETURN_STATUS EFIAPI AsciiStrCatS ( IN OUT CHAR8 Destination,
IN UINTN  DestMax,
IN CONST CHAR8 Source 
)

Appends a copy of the string pointed to by Source (including the terminating null char) to the end of the string pointed to by Destination.

If an error would be returned, then the function will also ASSERT().

Parameters:
Destination A pointer to a Null-terminated Ascii string.
DestMax The maximum number of Destination Ascii char, including terminating null char.
Source A pointer to a Null-terminated Ascii string.
Return values:
RETURN_SUCCESS String is appended.
RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than StrLen(Destination).
RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT greater than StrLen(Source).
RETURN_INVALID_PARAMETER If Destination is NULL. If Source is NULL. If PcdMaximumAsciiStringLength is not zero, and DestMax is greater than PcdMaximumAsciiStringLength. If DestMax is 0.
RETURN_ACCESS_DENIED If Source and Destination overlap.

References ASCII_RSIZE_MAX, AsciiStrnLenS(), InternalSafeStringNoAsciiStrOverlap(), NULL, RETURN_ACCESS_DENIED, RETURN_BAD_BUFFER_SIZE, RETURN_BUFFER_TOO_SMALL, RETURN_INVALID_PARAMETER, RETURN_SUCCESS, and SAFE_STRING_CONSTRAINT_CHECK.

RETURN_STATUS EFIAPI AsciiStrCpyS ( OUT CHAR8 Destination,
IN UINTN  DestMax,
IN CONST CHAR8 Source 
)

Copies the string pointed to by Source (including the terminating null char) to the array pointed to by Destination.

If an error would be returned, then the function will also ASSERT().

Parameters:
Destination A pointer to a Null-terminated Ascii string.
DestMax The maximum number of Destination Ascii char, including terminating null char.
Source A pointer to a Null-terminated Ascii string.
Return values:
RETURN_SUCCESS String is copied.
RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).
RETURN_INVALID_PARAMETER If Destination is NULL. If Source is NULL. If PcdMaximumAsciiStringLength is not zero, and DestMax is greater than PcdMaximumAsciiStringLength. If DestMax is 0.
RETURN_ACCESS_DENIED If Source and Destination overlap.

References ASCII_RSIZE_MAX, AsciiStrnLenS(), InternalSafeStringNoAsciiStrOverlap(), NULL, RETURN_ACCESS_DENIED, RETURN_BUFFER_TOO_SMALL, RETURN_INVALID_PARAMETER, RETURN_SUCCESS, and SAFE_STRING_CONSTRAINT_CHECK.

RETURN_STATUS EFIAPI AsciiStrnCatS ( IN OUT CHAR8 Destination,
IN UINTN  DestMax,
IN CONST CHAR8 Source,
IN UINTN  Length 
)

Appends not more than Length successive char from the string pointed to by Source to the end of the string pointed to by Destination. If no null char is copied from Source, then Destination[StrLen(Destination) + Length] is always set to null.

If an error would be returned, then the function will also ASSERT().

Parameters:
Destination A pointer to a Null-terminated Ascii string.
DestMax The maximum number of Destination Ascii char, including terminating null char.
Source A pointer to a Null-terminated Ascii string.
Length The maximum number of Ascii characters to copy.
Return values:
RETURN_SUCCESS String is appended.
RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than StrLen(Destination).
RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT greater than MIN(StrLen(Source), Length).
RETURN_INVALID_PARAMETER If Destination is NULL. If Source is NULL. If PcdMaximumAsciiStringLength is not zero, and DestMax is greater than PcdMaximumAsciiStringLength. If DestMax is 0.
RETURN_ACCESS_DENIED If Source and Destination overlap.

References ASCII_RSIZE_MAX, AsciiStrnLenS(), InternalSafeStringNoAsciiStrOverlap(), NULL, RETURN_ACCESS_DENIED, RETURN_BAD_BUFFER_SIZE, RETURN_BUFFER_TOO_SMALL, RETURN_INVALID_PARAMETER, RETURN_SUCCESS, and SAFE_STRING_CONSTRAINT_CHECK.

RETURN_STATUS EFIAPI AsciiStrnCpyS ( OUT CHAR8 Destination,
IN UINTN  DestMax,
IN CONST CHAR8 Source,
IN UINTN  Length 
)

Copies not more than Length successive char from the string pointed to by Source to the array pointed to by Destination. If no null char is copied from Source, then Destination[Length] is always set to null.

If an error would be returned, then the function will also ASSERT().

Parameters:
Destination A pointer to a Null-terminated Ascii string.
DestMax The maximum number of Destination Ascii char, including terminating null char.
Source A pointer to a Null-terminated Ascii string.
Length The maximum number of Ascii characters to copy.
Return values:
RETURN_SUCCESS String is copied.
RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than MIN(StrLen(Source), Length).
RETURN_INVALID_PARAMETER If Destination is NULL. If Source is NULL. If PcdMaximumAsciiStringLength is not zero, and DestMax is greater than PcdMaximumAsciiStringLength. If DestMax is 0.
RETURN_ACCESS_DENIED If Source and Destination overlap.

References ASCII_RSIZE_MAX, AsciiStrnLenS(), InternalSafeStringNoAsciiStrOverlap(), NULL, RETURN_ACCESS_DENIED, RETURN_BUFFER_TOO_SMALL, RETURN_INVALID_PARAMETER, RETURN_SUCCESS, and SAFE_STRING_CONSTRAINT_CHECK.

UINTN EFIAPI AsciiStrnLenS ( IN CONST CHAR8 String,
IN UINTN  MaxSize 
)

Returns the length of a Null-terminated Ascii string.

Parameters:
String A pointer to a Null-terminated Ascii string.
MaxSize The maximum number of Destination Ascii char, including terminating null char.
Return values:
0 If String is NULL.
MaxSize If there is no null character in the first MaxSize characters of String.
Returns:
The number of characters that percede the terminating null character.

References NULL.

Referenced by AsciiStrCatS(), AsciiStrCpyS(), AsciiStrnCatS(), and AsciiStrnCpyS().

BOOLEAN InternalSafeStringIsOverlap ( IN VOID *  Base1,
IN UINTN  Size1,
IN VOID *  Base2,
IN UINTN  Size2 
)

Returns if 2 memory blocks are overlapped.

Parameters:
Base1 Base address of 1st memory block.
Size1 Size of 1st memory block.
Base2 Base address of 2nd memory block.
Size2 Size of 2nd memory block.
Return values:
TRUE 2 memory blocks are overlapped.
FALSE 2 memory blocks are not overlapped.

References FALSE, and TRUE.

Referenced by InternalSafeStringNoAsciiStrOverlap(), and InternalSafeStringNoStrOverlap().

BOOLEAN InternalSafeStringNoAsciiStrOverlap ( IN CHAR8 Str1,
IN UINTN  Size1,
IN CHAR8 Str2,
IN UINTN  Size2 
)

Returns if 2 Ascii strings are not overlapped.

Parameters:
Str1 Start address of 1st Ascii string.
Size1 The number of char in 1st Ascii string, including terminating null char.
Str2 Start address of 2nd Ascii string.
Size2 The number of char in 2nd Ascii string, including terminating null char.
Return values:
TRUE 2 Ascii strings are NOT overlapped.
FALSE 2 Ascii strings are overlapped.

References InternalSafeStringIsOverlap().

Referenced by AsciiStrCatS(), AsciiStrCpyS(), AsciiStrnCatS(), and AsciiStrnCpyS().

BOOLEAN InternalSafeStringNoStrOverlap ( IN CHAR16 Str1,
IN UINTN  Size1,
IN CHAR16 Str2,
IN UINTN  Size2 
)

Returns if 2 Unicode strings are not overlapped.

Parameters:
Str1 Start address of 1st Unicode string.
Size1 The number of char in 1st Unicode string, including terminating null char.
Str2 Start address of 2nd Unicode string.
Size2 The number of char in 2nd Unicode string, including terminating null char.
Return values:
TRUE 2 Unicode strings are NOT overlapped.
FALSE 2 Unicode strings are overlapped.

References InternalSafeStringIsOverlap().

Referenced by StrCatS(), StrCpyS(), StrnCatS(), and StrnCpyS().

RETURN_STATUS EFIAPI StrCatS ( IN OUT CHAR16 Destination,
IN UINTN  DestMax,
IN CONST CHAR16 Source 
)

Appends a copy of the string pointed to by Source (including the terminating null char) to the end of the string pointed to by Destination.

If Destination is not aligned on a 16-bit boundary, then ASSERT(). If Source is not aligned on a 16-bit boundary, then ASSERT(). If an error would be returned, then the function will also ASSERT().

Parameters:
Destination A pointer to a Null-terminated Unicode string.
DestMax The maximum number of Destination Unicode char, including terminating null char.
Source A pointer to a Null-terminated Unicode string.
Return values:
RETURN_SUCCESS String is appended.
RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than StrLen(Destination).
RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT greater than StrLen(Source).
RETURN_INVALID_PARAMETER If Destination is NULL. If Source is NULL. If PcdMaximumUnicodeStringLength is not zero, and DestMax is greater than PcdMaximumUnicodeStringLength. If DestMax is 0.
RETURN_ACCESS_DENIED If Source and Destination overlap.

References ASSERT, BIT0, InternalSafeStringNoStrOverlap(), NULL, RETURN_ACCESS_DENIED, RETURN_BAD_BUFFER_SIZE, RETURN_BUFFER_TOO_SMALL, RETURN_INVALID_PARAMETER, RETURN_SUCCESS, RSIZE_MAX, SAFE_STRING_CONSTRAINT_CHECK, and StrnLenS().

Referenced by CreatePopUp().

RETURN_STATUS EFIAPI StrCpyS ( OUT CHAR16 Destination,
IN UINTN  DestMax,
IN CONST CHAR16 Source 
)

Copies the string pointed to by Source (including the terminating null char) to the array pointed to by Destination.

If Destination is not aligned on a 16-bit boundary, then ASSERT(). If Source is not aligned on a 16-bit boundary, then ASSERT(). If an error would be returned, then the function will also ASSERT().

Parameters:
Destination A pointer to a Null-terminated Unicode string.
DestMax The maximum number of Destination Unicode char, including terminating null char.
Source A pointer to a Null-terminated Unicode string.
Return values:
RETURN_SUCCESS String is copied.
RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).
RETURN_INVALID_PARAMETER If Destination is NULL. If Source is NULL. If PcdMaximumUnicodeStringLength is not zero, and DestMax is greater than PcdMaximumUnicodeStringLength. If DestMax is 0.
RETURN_ACCESS_DENIED If Source and Destination overlap.

References ASSERT, BIT0, InternalSafeStringNoStrOverlap(), NULL, RETURN_ACCESS_DENIED, RETURN_BUFFER_TOO_SMALL, RETURN_INVALID_PARAMETER, RETURN_SUCCESS, RSIZE_MAX, SAFE_STRING_CONSTRAINT_CHECK, and StrnLenS().

Referenced by CatVSPrint(), DevPathFromTextBluetooth(), and DevPathFromTextFilePath().

RETURN_STATUS EFIAPI StrnCatS ( IN OUT CHAR16 Destination,
IN UINTN  DestMax,
IN CONST CHAR16 Source,
IN UINTN  Length 
)

Appends not more than Length successive char from the string pointed to by Source to the end of the string pointed to by Destination. If no null char is copied from Source, then Destination[StrLen(Destination) + Length] is always set to null.

If Destination is not aligned on a 16-bit boundary, then ASSERT(). If Source is not aligned on a 16-bit boundary, then ASSERT(). If an error would be returned, then the function will also ASSERT().

Parameters:
Destination A pointer to a Null-terminated Unicode string.
DestMax The maximum number of Destination Unicode char, including terminating null char.
Source A pointer to a Null-terminated Unicode string.
Length The maximum number of Unicode characters to copy.
Return values:
RETURN_SUCCESS String is appended.
RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than StrLen(Destination).
RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT greater than MIN(StrLen(Source), Length).
RETURN_INVALID_PARAMETER If Destination is NULL. If Source is NULL. If PcdMaximumUnicodeStringLength is not zero, and DestMax is greater than PcdMaximumUnicodeStringLength. If DestMax is 0.
RETURN_ACCESS_DENIED If Source and Destination overlap.

References ASSERT, BIT0, InternalSafeStringNoStrOverlap(), NULL, RETURN_ACCESS_DENIED, RETURN_BAD_BUFFER_SIZE, RETURN_BUFFER_TOO_SMALL, RETURN_INVALID_PARAMETER, RETURN_SUCCESS, RSIZE_MAX, SAFE_STRING_CONSTRAINT_CHECK, and StrnLenS().

Referenced by DevPathFromTextBluetooth().

RETURN_STATUS EFIAPI StrnCpyS ( OUT CHAR16 Destination,
IN UINTN  DestMax,
IN CONST CHAR16 Source,
IN UINTN  Length 
)

Copies not more than Length successive char from the string pointed to by Source to the array pointed to by Destination. If no null char is copied from Source, then Destination[Length] is always set to null.

If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT(). If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT(). If an error would be returned, then the function will also ASSERT().

Parameters:
Destination A pointer to a Null-terminated Unicode string.
DestMax The maximum number of Destination Unicode char, including terminating null char.
Source A pointer to a Null-terminated Unicode string.
Length The maximum number of Unicode characters to copy.
Return values:
RETURN_SUCCESS String is copied.
RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than MIN(StrLen(Source), Length).
RETURN_INVALID_PARAMETER If Destination is NULL. If Source is NULL. If PcdMaximumUnicodeStringLength is not zero, and DestMax is greater than PcdMaximumUnicodeStringLength. If DestMax is 0.
RETURN_ACCESS_DENIED If Source and Destination overlap.

References ASSERT, BIT0, InternalSafeStringNoStrOverlap(), NULL, RETURN_ACCESS_DENIED, RETURN_BUFFER_TOO_SMALL, RETURN_INVALID_PARAMETER, RETURN_SUCCESS, RSIZE_MAX, SAFE_STRING_CONSTRAINT_CHECK, and StrnLenS().

Referenced by CreatePopUp().

UINTN EFIAPI StrnLenS ( IN CONST CHAR16 String,
IN UINTN  MaxSize 
)

Returns the length of a Null-terminated Unicode string.

If String is not aligned on a 16-bit boundary, then ASSERT().

Parameters:
String A pointer to a Null-terminated Unicode string.
MaxSize The maximum number of Destination Unicode char, including terminating null char.
Return values:
0 If String is NULL.
MaxSize If there is no null character in the first MaxSize characters of String.
Returns:
The number of characters that percede the terminating null character.

References ASSERT, BIT0, and NULL.

Referenced by DevPathFromTextUri(), StrCatS(), StrCpyS(), StrnCatS(), and StrnCpyS().


Generated on Thu Sep 24 23:14:22 2015 for MdePkg[ALL] by  doxygen 1.5.7.1