summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2022-12-15 11:45:48 +0100
committerTomas Mraz <tomas@openssl.org>2022-12-22 11:35:12 +0100
commite1f09938ca69b080467112efa3111213042ff8db (patch)
tree165f981c3325a85fb52e51fccbecbb45b7f62ba5 /crypto
parent0c5fe6e4e740e7150ecb9f0a1954ef085f1fcf10 (diff)
Avoid ifdefs in trace categories
The trace code assumes all categories are present and the category numbers are equal to the index in the table. Fixes #19915 Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> (Merged from https://github.com/openssl/openssl/pull/19917) (cherry picked from commit 78bd646b2f6a18cf8515e05a5f3efadff03b3920)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/trace.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/crypto/trace.c b/crypto/trace.c
index 0d58932825..74dbd525a5 100644
--- a/crypto/trace.c
+++ b/crypto/trace.c
@@ -118,17 +118,16 @@ struct trace_category_st {
};
#define TRACE_CATEGORY_(name) { #name, OSSL_TRACE_CATEGORY_##name }
-static const struct trace_category_st trace_categories[] = {
+static const struct trace_category_st
+ trace_categories[OSSL_TRACE_CATEGORY_NUM] = {
TRACE_CATEGORY_(ALL),
TRACE_CATEGORY_(TRACE),
TRACE_CATEGORY_(INIT),
TRACE_CATEGORY_(TLS),
TRACE_CATEGORY_(TLS_CIPHER),
TRACE_CATEGORY_(CONF),
-#ifndef OPENSSL_NO_ENGINE
TRACE_CATEGORY_(ENGINE_TABLE),
TRACE_CATEGORY_(ENGINE_REF_COUNT),
-#endif
TRACE_CATEGORY_(PKCS5V2),
TRACE_CATEGORY_(PKCS12_KEYGEN),
TRACE_CATEGORY_(PKCS12_DECRYPT),
@@ -144,22 +143,16 @@ static const struct trace_category_st trace_categories[] = {
const char *OSSL_trace_get_category_name(int num)
{
- size_t i;
-
+ if (num < 0 || (size_t)num >= OSSL_NELEM(trace_categories))
+ return NULL;
/*
* Partial check that OSSL_TRACE_CATEGORY_... macros
* are synced with trace_categories array
*/
-#ifndef OPENSSL_NO_ENGINE
- if (!ossl_assert(OSSL_TRACE_CATEGORY_NUM == OSSL_NELEM(trace_categories)))
+ if (!ossl_assert(trace_categories[num].name != NULL)
+ || !ossl_assert(trace_categories[num].num == num))
return NULL;
-#endif
-
- for (i = 0; i < OSSL_NELEM(trace_categories); i++)
- if (trace_categories[i].num == num)
- return trace_categories[i].name;
-
- return NULL; /* not found */
+ return trace_categories[num].name;
}
int OSSL_trace_get_category_num(const char *name)