Skip to content

Commit

Permalink
[FIX] create hexdump_zxid to aid debugging
Browse files Browse the repository at this point in the history
There is a function hexdump that is being shadowed by the system implementation. As the signature is the same, when passed our arguments there are cases where there is a memory leak.

The solution was to rename hexdump to hexdump_zxid and change all calls to it.
  • Loading branch information
Felipe Zipitria committed Jun 26, 2018
1 parent 8559f2f commit 134123e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions errmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,10 @@ extern FILE* errmac_debug_log; /* Defined in zxidlib.c as 0 alias to stderr *
#define DD_XML_BLOB(cf, lk, len, xml) /* Documentative */

int hexdmp(const char* msg, const void* p, int len, int max);
int hexdump(const char* msg, const void* p, const void* lim, int max);
int hexdump_zxid(const char* msg, const void* p, const void* lim, int max);

#define HEXDUMP(msg, p, lim, max) if ((errmac_debug&ERRMAC_DEBUG_MASK) > 1) hexdump((msg), (p), (lim), (max))

#define HEXDUMP(msg, p, lim, max) if ((errmac_debug&ERRMAC_DEBUG_MASK) > 1) hexdump_zxid((msg), (p), (lim), (max))
#define DHEXDUMP(msg, p, lim, max) /* Disabled hex dump */

#define DUMP_CORE() ASSERT(0)
Expand Down
16 changes: 8 additions & 8 deletions zxsig.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,8 @@ int zx_report_openssl_err(const char* logkey)
#endif

D("%s: len=%d data(%.*s)", lk, len, len, data);
DV("%s: data above %d", lk, hexdump("data: ", data, data+len, 4096));
DV("%s: digest above %d", lk, hexdump("digest: ", mdbuf, mdbuf+mdlen, 64));
DV("%s: data above %d", lk, hexdump_zxid("data: ", data, data+len, 4096));
DV("%s: digest above %d", lk, hexdump_zxid("digest: ", mdbuf, mdbuf+mdlen, 64));

if (!priv_key) {
ERR(priv_key_missing_msg, geteuid(), getegid());
Expand All @@ -864,7 +864,7 @@ int zx_report_openssl_err(const char* logkey)
if (RSA_sign(EVP_MD_type(evp_digest), mdbuf, mdlen, (unsigned char*)*sig, (unsigned int*)&len, rsa)) {
DD("data = %s, SHA1 sig = %s, siglen = %d", data, *sig, len);
D("RSA siglen = %d", len);
DV("%s: sig above %d", lk, hexdump("sig: ", *sig, *sig+len, 1024));
DV("%s: sig above %d", lk, hexdump_zxid("sig: ", *sig, *sig+len, 1024));
return len;
}
#else
Expand Down Expand Up @@ -1000,9 +1000,9 @@ int zxsig_verify_data(int len, char* data, int siglen, char* sig, X509* cert, co
else if (!strcmp(mdalg, "SHA512")) { SHA512((unsigned char*)data, len, mdbuf); nid = NID_sha512; }
else { SHA1((unsigned char*)data, len, mdbuf); nid = NID_sha1; }
#endif
DV("%s: vfy data len=%d above %d", lk, len, hexdump("data: ", data, data+len, 8192));
DV("%s: vfy sig above %d", lk, hexdump("sig: ", sig, sig+siglen, 8192));
DV("%s: vfy md above %d", lk, hexdump("md: ", mdbuf, mdbuf+64, 64));
DV("%s: vfy data len=%d above %d", lk, len, hexdump_zxid("data: ", data, data+len, 8192));
DV("%s: vfy sig above %d", lk, hexdump_zxid("sig: ", sig, sig+siglen, 8192));
DV("%s: vfy md above %d", lk, hexdump_zxid("md: ", mdbuf, mdbuf+64, 64));

evp_pubk = X509_get_pubkey(cert);
if (!evp_pubk) {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ int zxsig_verify_data(int len, char* data, int siglen, char* sig, X509* cert, co
if (!verdict) {
ERR("RSA signature verify in %s data failed. Perhaps you have bad or no certificate(%p) len=%d data=%p siglen=%d sig=%p", lk, cert, len, data, siglen, sig);
zx_report_openssl_err(lk);
D("RSA_vfy(%s) bad sig above %d", lk, hexdump("sig: ", sig, sig+siglen, 4096));
D("RSA_vfy(%s) bad sig above %d", lk, hexdump_zxid("sig: ", sig, sig+siglen, 4096));
return ZXSIG_VFY_FAIL;
} else {
D("RSA verify OK %d", verdict);
Expand Down Expand Up @@ -1073,7 +1073,7 @@ int zxsig_verify_data(int len, char* data, int siglen, char* sig, X509* cert, co
if (!verdict) {
ERR("DSA signature verify in %s data failed. Perhaps you have bad or no certificate(%p) len=%d data=%p siglen=%d sig=%p", lk, cert, len, data, siglen, sig);
zx_report_openssl_err(lk);
D("DSA_vfy(%s) sig above %d", lk, hexdump("sig: ", sig, sig+siglen, 4096));
D("DSA_vfy(%s) sig above %d", lk, hexdump_zxid("sig: ", sig, sig+siglen, 4096));
return ZXSIG_VFY_FAIL;
} else {
D("DSA verify OK %d", verdict);
Expand Down
4 changes: 2 additions & 2 deletions zxutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ int copy_file(const char* from, const char* to, const char* logkey, int may_link
/*() Output a hexdump to stderr. Used for debugging purposes. */

/* Called by: */
int hexdump(const char* msg, const void* data, const void* lim, int max)
int hexdump_zxid(const char* msg, const void* data, const void* lim, int max)
{
int i;
const char* p = (const char*)data;
Expand Down Expand Up @@ -720,7 +720,7 @@ int hexdump(const char* msg, const void* data, const void* lim, int max)

/* Called by: zx_get_symkey, zx_raw_cipher2 x4, zxbus_verify_receipt x2, zxsig_validate x19 */
int hexdmp(const char* msg, const void* p, int len, int max) {
return hexdump(msg, p, p+len, max);
return hexdump_zxid(msg, p, p+len, max);
}

/*
Expand Down

0 comments on commit 134123e

Please sign in to comment.