Commit 0c302613 authored by npzacs's avatar npzacs
Browse files

Fixed memleaks introduced in r452: make print_hex() use caller-supplied buffer

parent 6cc76c41
......@@ -43,12 +43,13 @@ int _validate_pk(uint8_t *pk, uint8_t *cvalue, uint8_t *uv, uint8_t *vd,
{
int a, ret = 0;
uint8_t dec_vd[16];
char str[40];
DEBUG(DBG_AACS, "Validate processing key %s...\n", print_hex(pk, 16));
DEBUG(DBG_AACS, "Validate processing key %s...\n", print_hex(str, pk, 16));
DEBUG(DBG_AACS, " Using:\n");
DEBUG(DBG_AACS, " UV: %s\n", print_hex(uv, 4));
DEBUG(DBG_AACS, " cvalue: %s\n", print_hex(cvalue, 16));
DEBUG(DBG_AACS, " Verification data: %s\n", print_hex(vd, 16));
DEBUG(DBG_AACS, " UV: %s\n", print_hex(str, uv, 4));
DEBUG(DBG_AACS, " cvalue: %s\n", print_hex(str, cvalue, 16));
DEBUG(DBG_AACS, " Verification data: %s\n", print_hex(str, vd, 16));
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_set_key_length(ctx, 16);
......@@ -108,7 +109,8 @@ int _calc_mk(AACS *aacs, const char *path)
mkb_close(mkb);
X_FREE(buf);
DEBUG(DBG_AACS, "Media key: %s\n", print_hex(aacs->mk,
char str[40];
DEBUG(DBG_AACS, "Media key: %s\n", print_hex(str, aacs->mk,
16));
return 1;
}
......@@ -151,7 +153,8 @@ int _calc_vuk(AACS *aacs, const char *path)
mmc_close(mmc);
DEBUG(DBG_AACS, "Volume unique key: %s\n", print_hex(aacs->vuk,
char str[40];
DEBUG(DBG_AACS, "Volume unique key: %s\n", print_hex(str, aacs->vuk,
16));
return 1;
......@@ -214,8 +217,9 @@ int _calc_uks(AACS *aacs, const char *path)
EVP_DecryptFinal(ctx, aacs->uks, (int*)16);
EVP_CIPHER_CTX_cleanup(ctx);
char str[40];
DEBUG(DBG_AACS, "Unit key %d: %s\n", i,
print_hex(aacs->uks + 16*i, 16));
print_hex(str, aacs->uks + 16*i, 16));
}
file_close(fp);
......@@ -271,6 +275,7 @@ int _find_vuk(AACS *aacs, const char *path)
int64_t f_size;
uint16_t num_vuks;
char f_name[100];
char str[48];
snprintf(f_name , 100, "/%s/AACS/Unit_Key_RO.inf", path);
......@@ -299,7 +304,7 @@ int _find_vuk(AACS *aacs, const char *path)
file_close(fp);
crypto_aacs_title_hash(ukf_buf, f_size, hash);
DEBUG(DBG_AACS, "Disc ID: %s\n", print_hex(hash, 20));
DEBUG(DBG_AACS, "Disc ID: %s\n", print_hex(str, hash, 20));
X_FREE(ukf_buf);
......@@ -315,7 +320,7 @@ int _find_vuk(AACS *aacs, const char *path)
memcpy(aacs->vuk, key_pos + 30, 16);
DEBUG(DBG_AACS, "Found volume unique key for %s: %s\n", desc,
print_hex(aacs->vuk, 16));
print_hex(str, aacs->vuk, 16));
return 1;
}
......
......@@ -76,12 +76,13 @@ static int _mmc_send_cmd(MMC *mmc, const uint8_t *cmd, uint8_t *buf, size_t tx,
int a = ioctl(mmc->fd, CDROM_SEND_PACKET, &cgc);
char str[512];
DEBUG(DBG_MMC, "Send LINUX MMC cmd %s: (%p)\n",
print_hex(cmd, 16), mmc);
print_hex(str, cmd, 16), mmc);
if (tx) {
DEBUG(DBG_MMC, " Buffer: %s -> (%p)\n", print_hex(buf, tx), mmc);
DEBUG(DBG_MMC, " Buffer: %s -> (%p)\n", print_hex(str, buf, tx), mmc);
} else {
DEBUG(DBG_MMC, " Buffer: %s <- (%p)\n", print_hex(buf, rx), mmc);
DEBUG(DBG_MMC, " Buffer: %s <- (%p)\n", print_hex(str, buf, rx), mmc);
}
mmc->sk = sense.sense_key & 0x0f;
......@@ -129,9 +130,10 @@ static int _mmc_send_key(MMC *mmc, uint8_t agid, uint8_t format, uint8_t *buf,
uint16_t len)
{
uint8_t cmd[16];
char str[512];
memset(cmd, 0, 16);
DEBUG(DBG_MMC, "MMC send key [%d] %s... (%p)\n", len, print_hex(buf, len),
DEBUG(DBG_MMC, "MMC send key [%d] %s... (%p)\n", len, print_hex(str, buf, len),
mmc);
cmd[0] = 0xa3;
......@@ -140,7 +142,7 @@ static int _mmc_send_key(MMC *mmc, uint8_t agid, uint8_t format, uint8_t *buf,
cmd[9] = len & 0xff;
cmd[10] = (agid << 6) | (format & 0x3f);
DEBUG(DBG_MMC, "cmd: %s (%p)\n", print_hex(cmd, 16), mmc);
DEBUG(DBG_MMC, "cmd: %s (%p)\n", print_hex(str, cmd, 16), mmc);
return _mmc_send_cmd(mmc, cmd, buf, len, 0);
}
......@@ -324,6 +326,7 @@ void mmc_close(MMC *mmc)
int mmc_read_vid(MMC *mmc, uint8_t *vid)
{
uint8_t agid = 0, hks[40], dn[20], dc[92], dkp[40], dks[40], mac[16];
char str[512];
memset(hks, 0, 40);
......@@ -354,9 +357,9 @@ int mmc_read_vid(MMC *mmc, uint8_t *vid)
"Drive doesn't give its certificate (%p)\n", mmc);
break;
}
//DEBUG(DBG_MMC, "Drive certificate : %s (%p)\n", print_hex(dc, 92),
//DEBUG(DBG_MMC, "Drive certificate : %s (%p)\n", print_hex(str, dc, 92),
// mmc);
//DEBUG(DBG_MMC, "Drive nonce : %s (%p)\n", print_hex(dn, 20),
//DEBUG(DBG_MMC, "Drive nonce : %s (%p)\n", print_hex(str, dn, 20),
// mmc);
// receive mmc key
......@@ -365,9 +368,9 @@ int mmc_read_vid(MMC *mmc, uint8_t *vid)
mmc);
break;
}
//DEBUG(DBG_MMC, "Drive key point : %s (%p)\n", print_hex(dkp, 40),
//DEBUG(DBG_MMC, "Drive key point : %s (%p)\n", print_hex(str, dkp, 40),
// mmc);
//DEBUG(DBG_MMC, "Drive key signature : %s (%p)\n", print_hex(dks, 40),
//DEBUG(DBG_MMC, "Drive key signature : %s (%p)\n", print_hex(str, dks, 40),
// mmc);
crypto_aacs_sign(mmc->host_cert, mmc->host_priv_key, hks, dn,
......@@ -378,15 +381,15 @@ int mmc_read_vid(MMC *mmc, uint8_t *vid)
DEBUG(DBG_MMC | DBG_CRIT, "Error sending host signature (%p)\n",
mmc);
DEBUG(DBG_MMC, "Host key signature : %s (%p)\n",
print_hex(hks, 40), mmc);
print_hex(str, hks, 40), mmc);
break;
}
} while (0);
if (_mmc_read_vid(mmc, agid, vid, mac)) {
DEBUG(DBG_MMC, "VID: %s (%p)\n", print_hex(vid, 16), mmc);
DEBUG(DBG_MMC, "MAC: %s (%p)\n", print_hex(mac, 16), mmc);
DEBUG(DBG_MMC, "VID: %s (%p)\n", print_hex(str, vid, 16), mmc);
DEBUG(DBG_MMC, "MAC: %s (%p)\n", print_hex(str, mac, 16), mmc);
_mmc_invalidate_agid(mmc, agid);
......
......@@ -33,11 +33,8 @@
#include <stdarg.h>
#include <string.h>
char *print_hex(const uint8_t *buf, int count)
char *print_hex(char *out, const uint8_t *buf, int count)
{
char *out = (char*)malloc(512);
memset(out, 0, 512);
int zz;
for(zz = 0; zz < count; zz++) {
sprintf(out + (zz * 2), "%02X", buf[zz]);
......
......@@ -54,7 +54,7 @@ enum debug_mask_enum {
typedef enum debug_mask_enum debug_mask_t;
char *print_hex(const uint8_t *str, int count);
char *print_hex(char *out, const uint8_t *str, int count);
void debug(const char *file, int line, uint32_t mask, const char *format, ...)
BD_ATTR_FORMAT_PRINTF(4,5);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment