The StrnLenS and AsciiStrnLenS functions, when presented with a string
with no terminating NULL in the first MaxSize characters will check
the character at String[MaxSize] before checking if Length < MaxSize.
(They return the correct value, but have accessed beyond the stated
limit in the process.)
Flip the order of the tests to prevent this behaviour.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17936
6f19259b-4bc3-4df7-8a09-
765794883524
// String then StrnLenS returns MaxSize. At most the first MaxSize characters of String shall\r
// be accessed by StrnLenS.\r
//\r
// String then StrnLenS returns MaxSize. At most the first MaxSize characters of String shall\r
// be accessed by StrnLenS.\r
//\r
- for (Length = 0; (*String != 0) && (Length < MaxSize); String++, Length++) {\r
+ for (Length = 0; (Length < MaxSize) && (*String != 0); String++, Length++) {\r
// String then AsciiStrnLenS returns MaxSize. At most the first MaxSize characters of String shall\r
// be accessed by AsciiStrnLenS.\r
//\r
// String then AsciiStrnLenS returns MaxSize. At most the first MaxSize characters of String shall\r
// be accessed by AsciiStrnLenS.\r
//\r
- for (Length = 0; (*String != 0) && (Length < MaxSize); String++, Length++) {\r
+ for (Length = 0; (Length < MaxSize) && (*String != 0); String++, Length++) {\r