]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Move types.h #undefs for wincrypt.h compatibility
authorSamuel Lee <saml@microsoft.com>
Mon, 11 Apr 2022 14:36:16 +0000 (15:36 +0100)
committerDr. Matthias St. Pierre <matthias.st.pierre@ncp-e.com>
Mon, 30 May 2022 05:19:14 +0000 (07:19 +0200)
+ Always undef the symbols that may have been #define-d
  by wincrypt.h after the first inclusion of types.h to
  avoid errors from wincrypt.h symbols being used to
  compile OpenSSL code
+ Also need to remove #pragma once for this approach to work
+ Define WINCRYPT_USE_SYMBOL_PREFIX to enable wincrypt
  symbol prefix at some point in future

Fixes #9981

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/18131)

include/openssl/types.h
test/build.info
test/build_wincrypt_test.c [new file with mode: 0644]

index de9f1665249f5db05a90ffe8550ee863d72b1f40..c28028681fcefafae966a71696d1b73ccc9020e6 100644 (file)
@@ -7,9 +7,21 @@
  * https://www.openssl.org/source/license.html
  */
 
+/*
+ * Unfortunate workaround to avoid symbol conflict with wincrypt.h
+ * See https://github.com/openssl/openssl/issues/9981
+ */
+#ifdef _WIN32
+# define WINCRYPT_USE_SYMBOL_PREFIX
+# undef X509_NAME
+# undef X509_EXTENSIONS
+# undef PKCS7_SIGNER_INFO
+# undef OCSP_REQUEST
+# undef OCSP_RESPONSE
+#endif
+
 #ifndef OPENSSL_TYPES_H
 # define OPENSSL_TYPES_H
-# pragma once
 
 # include <limits.h>
 
@@ -70,15 +82,6 @@ typedef struct ASN1_ITEM_st ASN1_ITEM;
 typedef struct asn1_pctx_st ASN1_PCTX;
 typedef struct asn1_sctx_st ASN1_SCTX;
 
-# ifdef _WIN32
-#  undef X509_NAME
-#  undef X509_EXTENSIONS
-#  undef PKCS7_ISSUER_AND_SERIAL
-#  undef PKCS7_SIGNER_INFO
-#  undef OCSP_REQUEST
-#  undef OCSP_RESPONSE
-# endif
-
 # ifdef BIGNUM
 #  undef BIGNUM
 # endif
index a6dffe280e6af90665ddc8dd29a665445116ad68..fd7289053991d650a50663a47a27ed23bc8b2426 100644 (file)
@@ -58,7 +58,7 @@ IF[{- !$disabled{tests} -}]
           recordlentest drbgtest rand_status_test sslbuffertest \
           time_offset_test pemtest ssl_cert_table_internal_test ciphername_test \
           http_test servername_test ocspapitest fatalerrtest tls13ccstest \
-          sysdefaulttest errtest ssl_ctx_test \
+          sysdefaulttest errtest ssl_ctx_test build_wincrypt_test \
           context_internal_test aesgcmtest params_test evp_pkey_dparams_test \
           keymgmt_internal_test hexstr_test provider_status_test defltfips_test \
           bio_readbuffer_test user_property_test pkcs7_test upcallstest \
@@ -930,6 +930,10 @@ ENDIF
   INCLUDE[ssl_ctx_test]=../include ../apps/include
   DEPEND[ssl_ctx_test]=../libcrypto ../libssl libtestutil.a
 
+  SOURCE[build_wincrypt_test]=build_wincrypt_test.c
+  INCLUDE[build_wincrypt_test]=../include
+  DEPEND[build_wincrypt_test]=../libssl ../libcrypto
+
 {-
    use File::Spec::Functions;
    use File::Basename;
diff --git a/test/build_wincrypt_test.c b/test/build_wincrypt_test.c
new file mode 100644 (file)
index 0000000..5bd75e6
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/*
+ * Simple buildtest to check for symbol collisions between wincrypt and
+ * OpenSSL headers
+ */
+
+#include <openssl/types.h>
+
+#ifdef _WIN32
+# ifndef WIN32_LEAN_AND_MEAN
+#  define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+# include <wincrypt.h>
+# ifndef X509_NAME
+#  ifndef PEDANTIC
+#   warning "wincrypt.h no longer defining X509_NAME before OpenSSL headers"
+#  endif
+# endif
+#endif
+
+#include <openssl/opensslconf.h>
+#ifndef OPENSSL_NO_STDIO
+# include <stdio.h>
+#endif
+
+#include <openssl/evp.h>
+#include <openssl/x509.h>
+#include <openssl/x509v3.h>
+
+int main(void)
+{
+    return 0;
+}