public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Qin Long <qin.long@intel.com>
To: edk2-devel@lists.01.org
Cc: ting.ye@intel.com, jiaxin.wu@intel.com, lersek@redhat.com,
	ard.biesheuvel@linaro.org, glin@suse.com, ronald.cron@arm.com,
	Moso.Lee@citrix.com, thomas.palmer@hpe.com,
	David Woodhouse <dwmw2@infradead.org>
Subject: [PATCH v2 06/11] CryptoPkg: Fix handling of &strcmp function pointers
Date: Thu, 23 Mar 2017 21:19:27 +0800	[thread overview]
Message-ID: <20170323131932.6168-7-qin.long@intel.com> (raw)
In-Reply-To: <20170323131932.6168-1-qin.long@intel.com>

In a couple of places, OpenSSL code uses the address of the
strcmp() function, and assigns it to another comparator function
pointer.

Unfortunately, this falls foul of the inconsistent function ABI
that we use in EDKII. We '#define strcmp AsciiStrCmp' but AsciiStrCmp
is an EFIAPI function with the Microsoft ABI. And we're assigning its
address to a non-EFIAPI function, which may well have a different ABI.

Fix this by providing an actual strcmp() function in the default ABI.
We already *had* a prototype for it in OpenSslSupport.h, which was
then superseded by the #define strcmp AsciiStrCmp.

Now, OpenSSL code *can* use &strcmp without problems.

Cc: Ting Ye <ting.ye@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Gary Lin <glin@suse.com>
Cc: Ronald Cron <ronald.cron@arm.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Qin Long <qin.long@intel.com>
---
 CryptoPkg/Include/OpenSslSupport.h                | 3 +--
 CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c | 8 +++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/CryptoPkg/Include/OpenSslSupport.h b/CryptoPkg/Include/OpenSslSupport.h
index e011a7cfee..e6858a94a4 100644
--- a/CryptoPkg/Include/OpenSslSupport.h
+++ b/CryptoPkg/Include/OpenSslSupport.h
@@ -1,7 +1,7 @@
 /** @file
   Root include file to support building OpenSSL Crypto Library.
 
-Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
 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
@@ -276,7 +276,6 @@ extern FILE  *stdout;
 #define memchr(buf,ch,count)              ScanMem8(buf,(UINTN)(count),(UINT8)ch)
 #define memcmp(buf1,buf2,count)           (int)(CompareMem(buf1,buf2,(UINTN)(count)))
 #define memmove(dest,source,count)        CopyMem(dest,source,(UINTN)(count))
-#define strcmp                            AsciiStrCmp
 #define strncmp(string1,string2,count)    (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
 #define strcpy(strDest,strSource)         AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
 #define strncpy(strDest,strSource,count)  AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
diff --git a/CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c b/CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c
index 9d6867ebce..e8a76d07ff 100644
--- a/CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c
+++ b/CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c
@@ -2,7 +2,7 @@
   Intrinsic Memory Routines Wrapper Implementation for OpenSSL-based
   Cryptographic Library.
 
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
 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
@@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 #include <Base.h>
 #include <Library/BaseMemoryLib.h>
+#include <Library/BaseLib.h>
 
 /* OpenSSL will use floating point support, and C compiler produces the _fltused
    symbol by default. Simply define this symbol here to satisfy the linker. */
@@ -44,3 +45,8 @@ void * memset (void *dest, char ch, unsigned int count)
   
   return dest;
 }
+
+int strcmp (const char *s1, const char *s2)
+{
+  return (int)AsciiStrCmp(s1, s2);
+}
-- 
2.11.1.windows.1



  parent reply	other threads:[~2017-03-23 13:20 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-23 13:19 [PATCH v2 00/11] Upgrade CryptoPkg to use the OpenSSL 1.1.0xx/stable release Qin Long
2017-03-23 13:19 ` [PATCH v2 01/11] CryptoPkg/OpensslLib: Update INF files to support OpenSSL-1.1.0x build Qin Long
2017-03-23 18:27   ` Laszlo Ersek
2017-03-27  9:40   ` Gary Lin
2017-03-23 13:19 ` [PATCH v2 02/11] CryptoPkg: Update .gitignore for OpenSSL source masking Qin Long
2017-03-23 18:28   ` Laszlo Ersek
2017-03-23 13:19 ` [PATCH v2 03/11] CryptoPkg/OpensslLib: Remove patch file and installation scripts Qin Long
2017-03-23 18:28   ` Laszlo Ersek
2017-03-23 13:19 ` [PATCH v2 04/11] CryptoPkg/OpensslLib: Add new Perl script for file list generation Qin Long
2017-03-23 18:29   ` Laszlo Ersek
2017-03-23 13:19 ` [PATCH v2 05/11] CryptoPkg/OpensslLib: Add new OpenSSL-HOWTO document Qin Long
2017-03-23 18:31   ` Laszlo Ersek
2017-03-27  9:58   ` Gary Lin
2017-03-23 13:19 ` Qin Long [this message]
2017-03-23 18:33   ` [PATCH v2 06/11] CryptoPkg: Fix handling of &strcmp function pointers Laszlo Ersek
2017-03-27  9:41   ` Gary Lin
2017-03-23 13:19 ` [PATCH v2 07/11] CryptoPkg: Clean-up CRT Library Wrapper Qin Long
2017-03-23 18:34   ` Laszlo Ersek
2017-03-27  9:42   ` Gary Lin
2017-03-30 17:33   ` Laszlo Ersek
2017-03-31  2:06     ` Long, Qin
2017-03-23 13:19 ` [PATCH v2 08/11] CryptoPkg: Add extra build option to disable VS build warning Qin Long
2017-03-23 13:19 ` [PATCH v2 09/11] CryptoPkg: Update HMAC Wrapper with opaque HMAC_CTX object Qin Long
2017-03-23 18:37   ` Laszlo Ersek
2017-03-27  9:56     ` Gary Lin
2017-03-23 13:19 ` [PATCH v2 10/11] CryptoPkg: Update PK Cipher Wrappers work with opaque objects Qin Long
2017-03-23 18:38   ` Laszlo Ersek
2017-03-27  9:44   ` Gary Lin
2017-03-23 13:19 ` [PATCH v2 11/11] CryptoPkg/TlsLib: Update TLS Wrapper to align with OpenSSL changes Qin Long
2017-03-23 16:23   ` Palmer, Thomas
2017-03-24  5:40   ` Wu, Jiaxin
2017-03-23 17:28 ` [PATCH v2 00/11] Upgrade CryptoPkg to use the OpenSSL 1.1.0xx/stable release Laszlo Ersek
2017-03-28  8:19 ` Ye, Ting

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=20170323131932.6168-7-qin.long@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