Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1752655441, "reponame":"openssl", "desc":"OpenSSL", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://warmcat.com/repo/openssl", "f":3, "items": [ {"schema":"libjg2-1", "cid":"2d9478c814da55298021bbefb34d342b", "commit": {"type":"commit", "time": 1527111294, "time_ofs": 18446744073709551376, "oid_tree": { "oid": "3e49b8444a3c29a076eac36a126b77d7891d2f5b", "alias": []}, "oid":{ "oid": "2de108dfa343c3e06eb98beb122cd06306bb12fd", "alias": []}, "msg": "Save and restore the Windows error around TlsGetValue.", "sig_commit": { "git_time": { "time": 1527111294, "offset": -240 }, "name": "David Benjamin", "email": "davidben@google.com", "md5": "97b59b4df088a52a925e8639cefc6fcc" }, "sig_author": { "git_time": { "time": 1526851470, "offset": -240 }, "name": "David Benjamin", "email": "davidben@google.com", "md5": "97b59b4df088a52a925e8639cefc6fcc" }}, "body": "Save and restore the Windows error around TlsGetValue.\n\nTlsGetValue clears the last error even on success, so that callers may\ndistinguish it successfully returning NULL or failing. This error-mangling\nbehavior interferes with the caller's use of GetLastError. In particular\nSSL_get_error queries the error queue to determine whether the caller should\nlook at the OS's errors. To avoid destroying state, save and restore the\nWindows error.\n\nFixes #6299.\n\nReviewed-by: Rich Salz \u003crsalz@openssl.org\u003e\n(Merged from https://github.com/openssl/openssl/pull/6316)\n" , "diff": "diff --git a/crypto/threads_win.c b/crypto/threads_win.c\nindex 1e5cf82..7fdbc1f 100644\n--- a/crypto/threads_win.c\n+++ b/crypto/threads_win.c\n@@ -101,7 +101,26 @@ int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))\n \n void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n {\n- return TlsGetValue(*key);\n+ DWORD last_error;\n+ void *ret;\n+\n+ /*\n+ * TlsGetValue clears the last error even on success, so that callers may\n+ * distinguish it successfully returning NULL or failing. It is documented\n+ * to never fail if the argument is a valid index from TlsAlloc, so we do\n+ * not need to handle this.\n+ *\n+ * However, this error-mangling behavior interferes with the caller's use of\n+ * GetLastError. In particular SSL_get_error queries the error queue to\n+ * determine whether the caller should look at the OS's errors. To avoid\n+ * destroying state, save and restore the Windows error.\n+ *\n+ * https://msdn.microsoft.com/en-us/library/windows/desktop/ms686812(v\u003dvs.85).aspx\n+ */\n+ last_error \u003d GetLastError();\n+ ret \u003d TlsGetValue(*key);\n+ SetLastError(last_error);\n+ return ret;\n }\n \n int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\ndiff --git a/test/build.info b/test/build.info\nindex c3a0904..000153d 100644\n--- a/test/build.info\n+++ b/test/build.info\n@@ -51,7 +51,7 @@ INCLUDE_MAIN___test_libtestutil_OLB \u003d /INCLUDE\u003dMAIN\n recordlentest drbgtest drbg_cavs_test sslbuffertest \u005c\n time_offset_test pemtest ssl_cert_table_internal_test ciphername_test \u005c\n servername_test ocspapitest rsa_mp_test fatalerrtest tls13ccstest \u005c\n- sysdefaulttest\n+ sysdefaulttest errtest\n \n SOURCE[versions]\u003dversions.c\n INCLUDE[versions]\u003d../include\n@@ -535,6 +535,10 @@ INCLUDE_MAIN___test_libtestutil_OLB \u003d /INCLUDE\u003dMAIN\n SOURCE[sysdefaulttest]\u003dsysdefaulttest.c\n INCLUDE[sysdefaulttest]\u003d../include\n DEPEND[sysdefaulttest]\u003d../libcrypto ../libssl libtestutil.a\n+\n+ SOURCE[errtest]\u003derrtest.c\n+ INCLUDE[errtest]\u003d../include\n+ DEPEND[errtest]\u003d../libcrypto libtestutil.a\n ENDIF\n \n {-\ndiff --git a/test/errtest.c b/test/errtest.c\nnew file mode 100644\nindex 0000000..e464d08\n--- /dev/null\n+++ b/test/errtest.c\n@@ -0,0 +1,39 @@\n+/*\n+ * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.\n+ *\n+ * Licensed under the OpenSSL license (the \u0022License\u0022). You may not use\n+ * this file except in compliance with the License. You can obtain a copy\n+ * in the file LICENSE in the source distribution or at\n+ * https://www.openssl.org/source/license.html\n+ */\n+\n+#include \u003copenssl/opensslconf.h\u003e\n+#include \u003copenssl/err.h\u003e\n+\n+#include \u0022testutil.h\u0022\n+\n+#if defined(OPENSSL_SYS_WINDOWS)\n+# include \u003cwindows.h\u003e\n+#else\n+# include \u003cerrno.h\u003e\n+#endif\n+\n+/* Test that querying the error queue preserves the OS error. */\n+static int preserves_system_error(void)\n+{\n+#if defined(OPENSSL_SYS_WINDOWS)\n+ SetLastError(ERROR_INVALID_FUNCTION);\n+ ERR_get_error();\n+ return TEST_int_eq(GetLastError(), ERROR_INVALID_FUNCTION);\n+#else\n+ errno \u003d EINVAL;\n+ ERR_get_error();\n+ return TEST_int_eq(errno, EINVAL);\n+#endif\n+}\n+\n+int setup_tests(void)\n+{\n+ ADD_TEST(preserves_system_error);\n+ return 1;\n+}\ndiff --git a/test/recipes/04-test_err.t b/test/recipes/04-test_err.t\nnew file mode 100644\nindex 0000000..dd7681a\n--- /dev/null\n+++ b/test/recipes/04-test_err.t\n@@ -0,0 +1,12 @@\n+#! /usr/bin/env perl\n+# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.\n+#\n+# Licensed under the OpenSSL license (the \u0022License\u0022). You may not use\n+# this file except in compliance with the License. You can obtain a copy\n+# in the file LICENSE in the source distribution or at\n+# https://www.openssl.org/source/license.html\n+\n+\n+use OpenSSL::Test::Simple;\n+\n+simple_test(\u0022test_err\u0022, \u0022errtest\u0022);\n","s":{"c":1752655441,"u": 35476}} ],"g": 37099,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}