提交 2d905f67 编写于 作者: P Pauli

Print thread IDs nicely.

Remove the union that effectively cast thread IDs to long integers before
display and instead print a hex dump of the entire object.

Refer #9191
Reviewed-by: NRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9194)
上级 ba434131
/* /*
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the Apache License 2.0 (the "License"). You may not use * 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 * this file except in compliance with the License. You can obtain a copy
...@@ -130,11 +130,8 @@ static size_t internal_trace_cb(const char *buf, size_t cnt, ...@@ -130,11 +130,8 @@ static size_t internal_trace_cb(const char *buf, size_t cnt,
{ {
int ret = 0; int ret = 0;
tracedata *trace_data = vdata; tracedata *trace_data = vdata;
union { char buffer[256], *hex;
CRYPTO_THREAD_ID tid; CRYPTO_THREAD_ID tid;
unsigned long ltid;
} tid;
char buffer[256];
switch (cmd) { switch (cmd) {
case OSSL_TRACE_CTRL_BEGIN: case OSSL_TRACE_CTRL_BEGIN:
...@@ -142,11 +139,11 @@ static size_t internal_trace_cb(const char *buf, size_t cnt, ...@@ -142,11 +139,11 @@ static size_t internal_trace_cb(const char *buf, size_t cnt,
return 0; return 0;
trace_data->ingroup = 1; trace_data->ingroup = 1;
tid.ltid = 0; tid = CRYPTO_THREAD_get_current_id();
tid.tid = CRYPTO_THREAD_get_current_id(); hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%s]:%s: ",
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%lx]:%s: ", tid.ltid, hex, OSSL_trace_get_category_name(category));
OSSL_trace_get_category_name(category)); OPENSSL_free(hex);
BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX, BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX,
strlen(buffer), buffer); strlen(buffer), buffer);
break; break;
......
/* /*
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the Apache License 2.0 (the "License"). You may not use * 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 * this file except in compliance with the License. You can obtain a copy
...@@ -16,27 +16,19 @@ ...@@ -16,27 +16,19 @@
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
void *u) void *u)
{ {
CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id();
unsigned long l; unsigned long l;
char buf[256]; char buf[256];
char buf2[4096]; char buf2[4096], *hex;
const char *file, *data; const char *file, *data;
int line, flags; int line, flags;
/*
* We don't know what kind of thing CRYPTO_THREAD_ID is. Here is our best
* attempt to convert it into something we can print.
*/
union {
CRYPTO_THREAD_ID tid;
unsigned long ltid;
} tid;
tid.ltid = 0;
tid.tid = CRYPTO_THREAD_get_current_id();
while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) { while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
ERR_error_string_n(l, buf, sizeof(buf)); ERR_error_string_n(l, buf, sizeof(buf));
BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf, hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
file, line, (flags & ERR_TXT_STRING) ? data : ""); BIO_snprintf(buf2, sizeof(buf2), "%s:%s:%s:%d:%s\n", hex, buf, file,
line, (flags & ERR_TXT_STRING) ? data : "");
OPENSSL_free(hex);
if (cb(buf2, strlen(buf2), u) <= 0) if (cb(buf2, strlen(buf2), u) <= 0)
break; /* abort outputting the error report */ break; /* abort outputting the error report */
} }
......
/* /*
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the Apache License 2.0 (the "License"). You may not use * 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 * this file except in compliance with the License. You can obtain a copy
...@@ -455,20 +455,11 @@ typedef struct mem_leak_st { ...@@ -455,20 +455,11 @@ typedef struct mem_leak_st {
static void print_leak(const MEM *m, MEM_LEAK *l) static void print_leak(const MEM *m, MEM_LEAK *l)
{ {
char buf[1024]; char buf[1024];
char *bufp = buf; char *bufp = buf, *hex;
size_t len = sizeof(buf), ami_cnt; size_t len = sizeof(buf), ami_cnt;
APP_INFO *amip; APP_INFO *amip;
int n; int n;
struct tm *lcl = NULL; struct tm *lcl = NULL;
/*
* Convert between CRYPTO_THREAD_ID (which could be anything at all) and
* a long. This may not be meaningful depending on what CRYPTO_THREAD_ID is
* but hopefully should give something sensible on most platforms
*/
union {
CRYPTO_THREAD_ID tid;
unsigned long ltid;
} tid;
CRYPTO_THREAD_ID ti; CRYPTO_THREAD_ID ti;
lcl = localtime(&m->time); lcl = localtime(&m->time);
...@@ -488,15 +479,11 @@ static void print_leak(const MEM *m, MEM_LEAK *l) ...@@ -488,15 +479,11 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
bufp += n; bufp += n;
len -= n; len -= n;
tid.ltid = 0; hex = OPENSSL_buf2hexstr((const unsigned char *)&m->threadid,
tid.tid = m->threadid; sizeof(m->threadid));
n = BIO_snprintf(bufp, len, "thread=%lu, ", tid.ltid); n = BIO_snprintf(bufp, len, "thread=%s, number=%d, address=%p\n", hex,
if (n <= 0) m->num, m->addr);
return; OPENSSL_free(hex);
bufp += n;
len -= n;
n = BIO_snprintf(bufp, len, "number=%d, address=%p\n", m->num, m->addr);
if (n <= 0) if (n <= 0)
return; return;
bufp += n; bufp += n;
...@@ -522,11 +509,12 @@ static void print_leak(const MEM *m, MEM_LEAK *l) ...@@ -522,11 +509,12 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
break; break;
memset(buf, '>', ami_cnt); memset(buf, '>', ami_cnt);
buf[ami_cnt] = '\0'; buf[ami_cnt] = '\0';
tid.ltid = 0; hex = OPENSSL_buf2hexstr((const unsigned char *)&amip->threadid,
tid.tid = amip->threadid; sizeof(amip->threadid));
n = BIO_snprintf(buf + ami_cnt, sizeof(buf) - ami_cnt, n = BIO_snprintf(buf + ami_cnt, sizeof(buf) - ami_cnt,
" thread=%lu, file=%s, line=%d, info=\"", "thread=%s, file=%s, line=%d, info=\"",
tid.ltid, amip->file, amip->line); hex, amip->file, amip->line);
OPENSSL_free(hex);
if (n <= 0) if (n <= 0)
break; break;
buf_len = ami_cnt + n; buf_len = ami_cnt + n;
......
/* /*
* Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. * Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the Apache License 2.0 (the "License"). You may not use * 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 * this file except in compliance with the License. You can obtain a copy
...@@ -24,21 +24,18 @@ static size_t internal_trace_cb(const char *buf, size_t cnt, ...@@ -24,21 +24,18 @@ static size_t internal_trace_cb(const char *buf, size_t cnt,
{ {
int ret = 0; int ret = 0;
tracedata *trace_data = vdata; tracedata *trace_data = vdata;
union { char buffer[256], *hex;
CRYPTO_THREAD_ID tid; CRYPTO_THREAD_ID tid;
unsigned long ltid;
} tid;
char buffer[256];
switch (cmd) { switch (cmd) {
case OSSL_TRACE_CTRL_BEGIN: case OSSL_TRACE_CTRL_BEGIN:
trace_data->ingroup = 1; trace_data->ingroup = 1;
tid.ltid = 0; tid = CRYPTO_THREAD_get_current_id();
tid.tid = CRYPTO_THREAD_get_current_id(); hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%s]:%s: ",
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%lx]:%s: ", tid.ltid, hex, OSSL_trace_get_category_name(category));
OSSL_trace_get_category_name(category)); OPENSSL_free(hex);
BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX, BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX,
strlen(buffer), buffer); strlen(buffer), buffer);
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册