From: "Gao, Zhichao" <zhichao.gao@intel.com>
To: devel@edk2.groups.io
Cc: Michael D Kinney <michael.d.kinney@intel.com>,
Liming Gao <liming.gao@intel.com>,
Marvin Hauser <mhaeuser@outlook.de>,
Laszlo Ersek <lersek@redhat.com>
Subject: [PATCH 2/3] MdePkg/BaseLib: Base64Decode: Make DestinationSize complied to spec
Date: Fri, 28 Jun 2019 11:57:45 +0800 [thread overview]
Message-ID: <20190628035746.24160-3-zhichao.gao@intel.com> (raw)
In-Reply-To: <20190628035746.24160-1-zhichao.gao@intel.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1891
DestinationSize is decripted as 'Set to bytes stored on return'.
Before return the status, set its converted bytes to be complied
to the decriptions.
DestinationIndex may be overflow if the *DestinationSize is bigger
than (MAX_ADDRESS - 1). Move its incrementation under condition
'DestinationIndex < *DestinationSize' to make sure it wouldn't be
overflow.
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Marvin Hauser <mhaeuser@outlook.de>
Cc: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
---
MdePkg/Library/BaseLib/String.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
index b86e7e9436..7ebc2ecddd 100644
--- a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ -1964,6 +1964,7 @@ Base64Decode (
// Check if SourceLength or DestinationSize is valid
//
if ((SourceLength >= (MAX_ADDRESS - (UINTN)Source)) || (*DestinationSize >= (MAX_ADDRESS - (UINTN)Destination))){
+ *DestinationSize = 0;
return RETURN_INVALID_PARAMETER;
}
@@ -1991,6 +1992,7 @@ Base64Decode (
// Only two '=' characters can be valid.
//
if (BufferSize < -2) {
+ *DestinationSize = 0;
return RETURN_INVALID_PARAMETER;
}
} else {
@@ -2002,6 +2004,7 @@ Base64Decode (
// valid character after an '=', will be flagged as an error.
//
if (BufferSize < 0) {
+ *DestinationSize = 0;
return RETURN_INVALID_PARAMETER;
}
ActualSourceLength++;
@@ -2013,6 +2016,7 @@ Base64Decode (
// ignore ' ', '\t', '\n', and '\r'.
//
if ((Chr != ' ') &&(Chr != '\t') &&(Chr != '\n') &&(Chr != '\r')) {
+ *DestinationSize = 0;
return RETURN_INVALID_PARAMETER;
}
}
@@ -2023,11 +2027,13 @@ Base64Decode (
// The Base64 character string must be a multiple of 4 character quantums.
//
if (ActualSourceLength % 4 != 0) {
+ *DestinationSize = 0;
return RETURN_INVALID_PARAMETER;
}
BufferSize += ActualSourceLength / 4 * 3;
if (BufferSize < 0) {
+ *DestinationSize = 0;
return RETURN_INVALID_PARAMETER;
}
@@ -2075,13 +2081,16 @@ Base64Decode (
// Due to the '=' special cases for the two bytes at the end,
// we have to check the length and not store the padding data
//
- if (DestinationIndex++ < *DestinationSize) {
+ if (DestinationIndex < *DestinationSize) {
+ DestinationIndex++;
*Destination++ = (UINT8) (Value >> 8);
}
- if (DestinationIndex++ < *DestinationSize) {
+ if (DestinationIndex < *DestinationSize) {
+ DestinationIndex++;
*Destination++ = (UINT8) Value;
}
}
+ *DestinationSize = DestinationIndex;
return RETURN_SUCCESS;
}
--
2.21.0.windows.1
next prev parent reply other threads:[~2019-06-28 4:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-28 3:57 [PATCH 0/3] MdePkg/BaseLib: Base64Decode: Make it follow its specification Gao, Zhichao
2019-06-28 3:57 ` [PATCH 1/3] MdePkg/BaseLib: Adjust the coding style in Base64Decode Gao, Zhichao
2019-06-28 14:26 ` [edk2-devel] " Laszlo Ersek
2019-07-01 9:24 ` Laszlo Ersek
2019-07-01 9:55 ` Laszlo Ersek
2019-06-28 3:57 ` Gao, Zhichao [this message]
2019-07-01 11:03 ` [edk2-devel] [PATCH 2/3] MdePkg/BaseLib: Base64Decode: Make DestinationSize complied to spec Laszlo Ersek
2019-06-28 3:57 ` [PATCH 3/3] MdePkg/BaseLib: Base64Decode: Add decription for RETURN_SUCCESS Gao, Zhichao
2019-07-01 9:54 ` [edk2-devel] " Laszlo Ersek
2019-06-28 14:28 ` [edk2-devel] [PATCH 0/3] MdePkg/BaseLib: Base64Decode: Make it follow its specification Laszlo Ersek
2019-07-01 11:02 ` Laszlo Ersek
2019-07-01 11:11 ` Laszlo Ersek
2019-07-01 18:01 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190628035746.24160-3-zhichao.gao@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox