summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-06-09 03:58:48 +0200
committerPauli <pauli@openssl.org>2021-06-10 10:11:45 +0200
commit5a9dbfc58ab280ec426ed013f5aed5a5660b938a (patch)
tree40ad95d2ba8f8541bbef477f00ced6a81cfbbb9e /test
parentAPPS: Restore the possibility to combine -pubout with -text (diff)
downloadopenssl-5a9dbfc58ab280ec426ed013f5aed5a5660b938a.tar.xz
openssl-5a9dbfc58ab280ec426ed013f5aed5a5660b938a.zip
err: clear flags better when clearing errors.
An attempt to clear an error with malloced data didn't clear the flags. Now it clears all flags except the malloced flag. Fixes #12530 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15667)
Diffstat (limited to 'test')
-rw-r--r--test/errtest.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/errtest.c b/test/errtest.c
index e19501a036..2d827ff893 100644
--- a/test/errtest.c
+++ b/test/errtest.c
@@ -287,6 +287,53 @@ static int test_marks(void)
return 1;
}
+static int test_clear_error(void)
+{
+ int flags = -1;
+ const char *data = NULL;
+ int res = 0;
+
+ /* Raise an error with data and clear it */
+ ERR_raise_data(0, 0, "hello %s", "world");
+ ERR_peek_error_data(&data, &flags);
+ if (!TEST_str_eq(data, "hello world")
+ || !TEST_int_eq(flags, ERR_TXT_STRING | ERR_TXT_MALLOCED))
+ goto err;
+ ERR_clear_error();
+
+ /* Raise a new error without data */
+ ERR_raise(0, 0);
+ ERR_peek_error_data(&data, &flags);
+ if (!TEST_str_eq(data, "")
+ || !TEST_int_eq(flags, ERR_TXT_MALLOCED))
+ goto err;
+ ERR_clear_error();
+
+ /* Raise a new error with data */
+ ERR_raise_data(0, 0, "goodbye %s world", "cruel");
+ ERR_peek_error_data(&data, &flags);
+ if (!TEST_str_eq(data, "goodbye cruel world")
+ || !TEST_int_eq(flags, ERR_TXT_STRING | ERR_TXT_MALLOCED))
+ goto err;
+ ERR_clear_error();
+
+ /*
+ * Raise a new error without data to check that the malloced storage
+ * is freed properly
+ */
+ ERR_raise(0, 0);
+ ERR_peek_error_data(&data, &flags);
+ if (!TEST_str_eq(data, "")
+ || !TEST_int_eq(flags, ERR_TXT_MALLOCED))
+ goto err;
+ ERR_clear_error();
+
+ res = 1;
+ err:
+ ERR_clear_error();
+ return res;
+}
+
int setup_tests(void)
{
ADD_TEST(preserves_system_error);
@@ -296,5 +343,6 @@ int setup_tests(void)
ADD_TEST(test_print_error_format);
#endif
ADD_TEST(test_marks);
+ ADD_TEST(test_clear_error);
return 1;
}