CryptoPkg/Crt: turn strchr() into a function (CVE-2019-14553)

According to the ISO C standard, strchr() is a function. We #define it as
a macro. Unfortunately, our macro evaluates the first argument ("str")
twice. If the expression passed for "str" has side effects, the behavior
may be undefined.

In a later patch in this series, we're going to resurrect "inet_pton.c"
(originally from the StdLib package), which calls strchr() just like that:

  strchr((xdigits = xdigits_l), ch)
  strchr((xdigits = xdigits_u), ch)

To enable this kind of function call, turn strchr() into a function.

Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Sivaraman Nainar <sivaramann@amiindia.co.in>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=960
CVE: CVE-2019-14553
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
This commit is contained in:
Laszlo Ersek
2019-10-24 16:44:08 +02:00
parent 2ca74e1a17
commit eb520d94db
2 changed files with 6 additions and 1 deletions

View File

@@ -115,6 +115,11 @@ QuickSortWorker (
// -- String Manipulation Routines --
//
char *strchr(const char *str, int ch)
{
return ScanMem8 (str, AsciiStrSize (str), (UINT8)ch);
}
/* Scan a string for the last occurrence of a character */
char *strrchr (const char *str, int c)
{