mirror of
https://github.com/openssl/openssl.git
synced 2025-03-31 20:10:45 +08:00
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)
This commit is contained in:
parent
5a8fcd27bb
commit
78bd646b2f
@ -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)
|
||||
|
@ -43,10 +43,8 @@ extern "C" {
|
||||
# define OSSL_TRACE_CATEGORY_TLS 3
|
||||
# define OSSL_TRACE_CATEGORY_TLS_CIPHER 4
|
||||
# define OSSL_TRACE_CATEGORY_CONF 5
|
||||
# ifndef OPENSSL_NO_ENGINE
|
||||
# define OSSL_TRACE_CATEGORY_ENGINE_TABLE 6
|
||||
# define OSSL_TRACE_CATEGORY_ENGINE_REF_COUNT 7
|
||||
# endif
|
||||
# define OSSL_TRACE_CATEGORY_ENGINE_TABLE 6
|
||||
# define OSSL_TRACE_CATEGORY_ENGINE_REF_COUNT 7
|
||||
# define OSSL_TRACE_CATEGORY_PKCS5V2 8
|
||||
# define OSSL_TRACE_CATEGORY_PKCS12_KEYGEN 9
|
||||
# define OSSL_TRACE_CATEGORY_PKCS12_DECRYPT 10
|
||||
|
Loading…
x
Reference in New Issue
Block a user