[CodeQL] XmlSupportPkg: Fixing CodeQL failures in this package (#173)

# Preface

Please ensure you have read the [contribution
docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior
to submitting the pull request. In particular,
[pull request
guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices).

## Description

Pointer overflow has undefined behavior according to the C and C++
standards.
This change will convert the pointer to `UINTN` prior to the comparison
and leverage
unsigned integer overflow, which is defined, to perform the overflow
check.

There is also an error involving variable comparison between different
width.

For each item, place an "x" in between `[` and `]` if true. Example:
`[x]`.
_(you can also check items in the GitHub UI)_

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [x] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

Verified functional on Q35 virtual platform.

## Integration Instructions

N/A

---------

Co-authored-by: Michael Kubacki <michael.kubacki@microsoft.com>
This commit is contained in:
kuqin12 2023-02-16 16:46:53 -08:00 коммит произвёл GitHub
Родитель a942b04d7d
Коммит 639069d2c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -996,7 +996,7 @@ BuildNodeList (
//
// See if we have a value.
//
for (UINT32 i = 0; i < Next.Run.ulCharacters; i++) {
for (UINT64 i = 0; i < Next.Run.ulCharacters; i++) {
if (!IsWhiteSpace (LocalHyperSpace[i])) {
// MS_CHANGE
NotWhiteSpace = TRUE;

Просмотреть файл

@ -4885,6 +4885,7 @@ RtlXmlCopyStringOut (
CHAR16 *pwszWriteEnd = (CHAR16 *)(((UINTN)pwszTarget) + cbInTarget);
VOID *pvCursor;
VOID *pvDocumentEnd;
UINTN TempPtrEnd;
if (pCbResult) {
*pCbResult = 0;
@ -4934,7 +4935,8 @@ RtlXmlCopyStringOut (
// Two chars required
//
else if (Result.Character < 0x110000) {
if (((pwszWriteEnd + 2) <= pwszWriteEnd) && (pwszWriteCursor != NULL)) {
TempPtrEnd = (UINTN)pwszWriteEnd;
if (((TempPtrEnd + (2 * sizeof (*pwszWriteEnd))) <= TempPtrEnd) && (pwszWriteCursor != NULL)) {
pwszWriteCursor[0] = (CHAR16)(((Result.Character - 0x10000) / 0x400) + 0xd800);
pwszWriteCursor[1] = (CHAR16)(((Result.Character - 0x10000) % 0x400) + 0xdc00);
}

Просмотреть файл

@ -2262,6 +2262,7 @@ RtlXmlExtentToString (
UINT32 Character;
BOOLEAN fConvertReferences;
UINT32 cbRequired = 0;
UINTN TempPtrEnd;
if (!pState || !pExtent || !pcbString || !pString) {
return RtlpReportXmlError (EFI_INVALID_PARAMETER);
@ -2317,7 +2318,8 @@ RtlXmlExtentToString (
// Two chars required
//
else if (Character < 0x110000) {
if ((pwszWriteEnd + 2) <= pwszWriteEnd) {
TempPtrEnd = (UINTN)pwszWriteEnd;
if ((TempPtrEnd + (2 * sizeof (*pwszWriteEnd))) <= TempPtrEnd) {
pwszWriteCursor[0] = (CHAR16)(((Character - 0x10000) / 0x400) + 0xd800);
pwszWriteCursor[1] = (CHAR16)(((Character - 0x10000) % 0x400) + 0xdc00);
pwszWriteCursor += 2;