summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2019-06-20 11:24:17 +1000
committerPauli <paul.dale@oracle.com>2019-06-21 08:29:44 +1000
commit2d905f6715453034d1f942a0237b0d2b9d57326c (patch)
tree5d658a96ab4a8dce668a4b925a3120317ecf2b41 /crypto
parentba4341316ce762f917f973bb4ac604062fb11724 (diff)
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: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9194)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/err/err_prn.c22
-rw-r--r--crypto/mem_dbg.c36
2 files changed, 19 insertions, 39 deletions
diff --git a/crypto/err/err_prn.c b/crypto/err/err_prn.c
index ba9a7c59ef..b43367f694 100644
--- a/crypto/err/err_prn.c
+++ b/crypto/err/err_prn.c
@@ -1,5 +1,5 @@
/*
- * 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
* this file except in compliance with the License. You can obtain a copy
@@ -16,27 +16,19 @@
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
void *u)
{
+ CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id();
unsigned long l;
char buf[256];
- char buf2[4096];
+ char buf2[4096], *hex;
const char *file, *data;
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) {
ERR_error_string_n(l, buf, sizeof(buf));
- BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf,
- file, line, (flags & ERR_TXT_STRING) ? data : "");
+ hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
+ 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)
break; /* abort outputting the error report */
}
diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c
index 703cc30c78..8fcdbeca9e 100644
--- a/crypto/mem_dbg.c
+++ b/crypto/mem_dbg.c
@@ -1,5 +1,5 @@
/*
- * 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
* this file except in compliance with the License. You can obtain a copy
@@ -455,20 +455,11 @@ typedef struct mem_leak_st {
static void print_leak(const MEM *m, MEM_LEAK *l)
{
char buf[1024];
- char *bufp = buf;
+ char *bufp = buf, *hex;
size_t len = sizeof(buf), ami_cnt;
APP_INFO *amip;
int n;
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;
lcl = localtime(&m->time);
@@ -488,15 +479,11 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
bufp += n;
len -= n;
- tid.ltid = 0;
- tid.tid = m->threadid;
- n = BIO_snprintf(bufp, len, "thread=%lu, ", tid.ltid);
- if (n <= 0)
- return;
- bufp += n;
- len -= n;
-
- n = BIO_snprintf(bufp, len, "number=%d, address=%p\n", m->num, m->addr);
+ hex = OPENSSL_buf2hexstr((const unsigned char *)&m->threadid,
+ sizeof(m->threadid));
+ n = BIO_snprintf(bufp, len, "thread=%s, number=%d, address=%p\n", hex,
+ m->num, m->addr);
+ OPENSSL_free(hex);
if (n <= 0)
return;
bufp += n;
@@ -522,11 +509,12 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
break;
memset(buf, '>', ami_cnt);
buf[ami_cnt] = '\0';
- tid.ltid = 0;
- tid.tid = amip->threadid;
+ hex = OPENSSL_buf2hexstr((const unsigned char *)&amip->threadid,
+ sizeof(amip->threadid));
n = BIO_snprintf(buf + ami_cnt, sizeof(buf) - ami_cnt,
- " thread=%lu, file=%s, line=%d, info=\"",
- tid.ltid, amip->file, amip->line);
+ "thread=%s, file=%s, line=%d, info=\"",
+ hex, amip->file, amip->line);
+ OPENSSL_free(hex);
if (n <= 0)
break;
buf_len = ami_cnt + n;