diff -up ldns-1.6.16/keys.c.dsa ldns-1.6.16/keys.c
--- ldns-1.6.16/keys.c.dsa 2012-08-31 14:03:18.000000000 +0200
+++ ldns-1.6.16/keys.c 2014-03-18 17:48:57.474128661 +0100
@@ -1314,7 +1314,6 @@ ldns_key_dsa2bin(unsigned char *data, DS
/* See RFC2536 */
*size = (uint16_t)BN_num_bytes(k->p);
T = (*size - 64) / 8;
- memcpy(data, &T, 1);
if (T > 8) {
fprintf(stderr, "DSA key with T > 8 (ie. > 1024 bits)");
@@ -1323,12 +1322,13 @@ ldns_key_dsa2bin(unsigned char *data, DS
}
/* size = 64 + (T * 8); */
+ memset(data, 0, 21 + *size * 3);
data[0] = (unsigned char)T;
BN_bn2bin(k->q, data + 1 ); /* 20 octects */
BN_bn2bin(k->p, data + 21 ); /* offset octects */
- BN_bn2bin(k->g, data + 21 + *size); /* offset octets */
- BN_bn2bin(k->pub_key, data + 21 + *size + *size); /* offset octets */
- *size = 21 + (*size * 3);
+ BN_bn2bin(k->g, data + 21 + *size * 2 - BN_num_bytes(k->g));
+ BN_bn2bin(k->pub_key,data + 21 + *size * 3 - BN_num_bytes(k->pub_key));
+ *size = 21 + *size * 3;
return true;
}