Commit Diff
Diff:
9aab71feef498ad1c535f2aa7786309131909a87
e3b77902e047919d6bb2b444214397276937cf8d
Commit:
e3b77902e047919d6bb2b444214397276937cf8d
Tree:
4cdc45d079aa898597fe12828f7bd79ca803f977
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Tue Dec 3 18:21:40 2019 UTC
Message:
This makes delphinusdnsd work on my octeon. The fix is to take out this little construct: u_int16_t *val; val = (u_int16_t *)somepointer; *val = htons(somevalue); I replaced it with pack16(somepointer, htons(somevalue)); Where the packXX() functions are strict alignment-safe. Much help gotten from OpenBSD-misc mailing list, special thanks to Theo de Raadt. Thank you also goes to the libasr authors whose code was so helpful. NOTE: the u_int16_t to u_int macsize in additional_tsig() fixes tsig answers on long zonefiles on big-endian hosts including octeon. Tested with OpenBSD/octeon (eta router) and OpenBSD/amd64 (beta host) for little endian support
blob - 624de4c622b805a61c683683d481423df3f66890
blob + 6fc1e370fe5552cd562e2122c2d6efdc2e8f8f72
--- additional.c
+++ additional.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: additional.c,v 1.29 2019/11/09 07:53:45 pjp Exp $
+ * $Id: additional.c,v 1.30 2019/12/03 18:21:40 pjp Exp $
*/
#include <sys/types.h>
@@ -77,6 +77,14 @@ int additional_nsec(char *, int, int, struct rbtree *,
int additional_nsec3(char *, int, int, struct rbtree *, char *, int, int);
int additional_tsig(struct question *, char *, int, int, int, int, HMAC_CTX *);
+extern void pack(char *, char *, int);
+extern void pack32(char *, u_int32_t);
+extern void pack16(char *, u_int16_t);
+extern void pack8(char *, u_int8_t);
+extern uint32_t unpack32(char *);
+extern uint16_t unpack16(char *);
+extern void unpack(char *, char *, int);
+
extern int compress_label(u_char *, int, int);
extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
@@ -390,9 +398,7 @@ int
additional_tsig(struct question *question, char *reply, int replylen, int offset, int request, int envelope, HMAC_CTX *tsigctx)
{
struct dns_tsigrr *answer, *ppanswer, *timers;
- u_int16_t *sval;
- u_int16_t macsize = 32;
- u_int32_t *lval;
+ u_int macsize = 32;
int tsignamelen;
int ppoffset = 0;
int ttlen = 0, rollback;
@@ -414,8 +420,7 @@ additional_tsig(struct question *question, char *reply
if (envelope > 1 || envelope < -1) {
ttlen = 0;
if (priordigest) {
- sval = (u_int16_t *)&tsig_timers[ttlen];
- *sval = htons(question->tsig.tsigmaclen);
+ pack16((char *)&tsig_timers[ttlen], htons(question->tsig.tsigmaclen));
ttlen += 2;
memcpy(&tsig_timers[ttlen], question->tsig.tsigmac, question->tsig.tsigmaclen);
@@ -431,14 +436,12 @@ additional_tsig(struct question *question, char *reply
if (request == 0) {
if (question->tsig.tsigerrorcode && question->tsig.tsigerrorcode != DNS_BADTIME) {
ppoffset = 0;
- sval = (u_int16_t *)&pseudo_packet[ppoffset];
- *sval = htons(0);
+ pack16(&pseudo_packet[ppoffset], 0);
ppoffset += 2;
} else {
/* RFC 2845 section 3.4.3 */
ppoffset = 0;
- sval = (u_int16_t *)&pseudo_packet[ppoffset];
- *sval = htons(question->tsig.tsigmaclen);
+ pack16(&pseudo_packet[ppoffset], htons(question->tsig.tsigmaclen));
ppoffset += 2;
memcpy(&pseudo_packet[ppoffset], question->tsig.tsigmac, question->tsig.tsigmaclen);
@@ -476,34 +479,28 @@ additional_tsig(struct question *question, char *reply
ppoffset += question->tsig.tsigkeylen;
/* type TSIG */
- sval = (u_int16_t *)&reply[offset];
- *sval = htons(DNS_TYPE_TSIG);
+ pack16(&reply[offset], htons(DNS_TYPE_TSIG));
offset += 2;
/* class ANY */
- sval = (u_int16_t *)&reply[offset];
- *sval = htons(DNS_CLASS_ANY);
+ pack16(&reply[offset], htons(DNS_CLASS_ANY));
offset += 2;
- sval = (u_int16_t *)&pseudo_packet[ppoffset];
- *sval = htons(DNS_CLASS_ANY);
+ pack16(&pseudo_packet[ppoffset], htons(DNS_CLASS_ANY));
ppoffset += 2;
/* ttl */
- lval = (u_int32_t *)&reply[offset];
- *lval = htonl(0);
+ pack32(&reply[offset], 0);
offset += 4;
- lval = (u_int32_t *)&pseudo_packet[ppoffset];
- *lval = htonl(0);
+ pack32(&pseudo_packet[ppoffset], 0);
ppoffset += 4;
/* rdlen */
- sval = (u_int16_t *)&reply[offset];
if (question->tsig.tsigerrorcode == DNS_BADTIME) {
- *sval = htons(2 + 8 + question->tsig.tsigalglen + question->tsig.tsigmaclen + 2 + 2 + 2 + 6);
+ pack16(&reply[offset], htons(2 + 8 + question->tsig.tsigalglen + question->tsig.tsigmaclen + 2 + 2 + 2 + 6));
} else {
- *sval = htons(2 + 8 + question->tsig.tsigalglen + question->tsig.tsigmaclen + 2 + 2 + 2);
+ pack16(&reply[offset], htons(2 + 8 + question->tsig.tsigalglen + question->tsig.tsigmaclen + 2 + 2 + 2));
}
offset += 2;
@@ -517,7 +514,6 @@ additional_tsig(struct question *question, char *reply
answer = (struct dns_tsigrr *)&reply[offset];
if (envelope > 1 || envelope < -1) {
answer->timefudge = htobe64(((u_int64_t)now << 16) | (300 & 0xffff));
- //answer->timefudge = question->tsig.tsig_timefudge;
} else {
if (request == 0 || envelope == 1) {
answer->timefudge = question->tsig.tsig_timefudge;
@@ -532,30 +528,24 @@ additional_tsig(struct question *question, char *reply
/* skip mac */
offset += question->tsig.tsigmaclen;
- sval = (u_int16_t *)&reply[offset];
- *sval = odh->id;
+ pack16(&reply[offset], odh->id);
offset += 2;
- sval = (u_int16_t *)&reply[offset];
- *sval = htons(question->tsig.tsigerrorcode);
+ pack16(&reply[offset], htons(question->tsig.tsigerrorcode));
offset += 2;
if (question->tsig.tsigerrorcode == DNS_BADTIME) {
- sval = (u_int16_t *)&reply[offset];
- *sval = htons(6);
+ pack16(&reply[offset], htons(6));
offset += 2;
- sval = (u_int16_t *)&reply[offset];
- *sval = 0;
+ pack16(&reply[offset], 0);
offset += 2;
- lval = (u_int32_t *)&reply[offset];
- *lval = htonl(now & 0xffffffff);
+ pack32(&reply[offset], htonl(now & 0xffffffff));
offset += 4;
} else {
- sval = (u_int16_t *)&reply[offset];
- *sval = htons(0);
+ pack16(&reply[offset], 0);
offset += 2;
}
@@ -568,26 +558,21 @@ additional_tsig(struct question *question, char *reply
/* error */
- sval = (u_int16_t *)&pseudo_packet[ppoffset];
- *sval = htons(question->tsig.tsigerrorcode);
+ pack16(&pseudo_packet[ppoffset], htons(question->tsig.tsigerrorcode));
ppoffset += 2;
/* other len */
if (question->tsig.tsigerrorcode == DNS_BADTIME) {
- sval = (u_int16_t *)&pseudo_packet[ppoffset];
- *sval = htons(6);
+ pack16(&pseudo_packet[ppoffset], htons(6));
ppoffset += 2;
- sval = (u_int16_t *)&pseudo_packet[ppoffset];
- *sval = 0;
+ pack16(&pseudo_packet[ppoffset], htons(0));
ppoffset += 2;
- lval = (u_int32_t *)&pseudo_packet[ppoffset];
- *lval = htonl(now & 0xffffffff);
+ pack32(&pseudo_packet[ppoffset], htonl(now & 0xffffffff));
ppoffset += 4;
} else {
- sval = (u_int16_t *)&pseudo_packet[ppoffset];
- *sval = htons(0);
+ pack16(&pseudo_packet[ppoffset], htons(0));
ppoffset += 2;
}
@@ -602,6 +587,7 @@ additional_tsig(struct question *question, char *reply
}
+ /* we need it for the else */
if (envelope % 89 == 0 || envelope == -2) {
macsize = 32;
HMAC_Final(tsigctx, (unsigned char *)&answer->mac[0], (u_int *)&macsize);
blob - 17ce7c4082265a9dd01df3680aca0f4e78428ebf
blob + d9a649a883563400fb9b1a5a482bd525e9880691
--- axfr.c
+++ axfr.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: axfr.c,v 1.36 2019/11/19 07:13:04 pjp Exp $
+ * $Id: axfr.c,v 1.37 2019/12/03 18:21:40 pjp Exp $
*/
#include <sys/types.h>
@@ -93,6 +93,14 @@ void notifypacket(int, void *, void *, int);
void notifyslaves(int *);
void reap(int);
+extern void pack(char *, char *, int);
+extern void pack32(char *, u_int32_t);
+extern void pack16(char *, u_int16_t);
+extern void pack8(char *, u_int8_t);
+extern uint32_t unpack32(char *);
+extern uint16_t unpack16(char *);
+extern void unpack(char *, char *, int);
+
extern int get_record_size(ddDB *, char *, int);
extern in_addr_t getmask(int);
extern int getmask6(int, struct sockaddr_in6 *);
@@ -837,8 +845,6 @@ axfr_connection(int so, char *address, int is_ipv6, dd
int rs;
int tsigkeylen;
- u_int16_t *tmp;
-
struct node *n, *nx;
struct dns_header *dh, *odh;
struct sreply sreply;
@@ -875,8 +881,8 @@ axfr_connection(int so, char *address, int is_ipv6, dd
* input is fragmented or not...
*/
if (offset + len >= 2) {
- tmp = (u_int16_t *)p;
- dnslen = ntohs(*tmp);
+ dnslen = unpack16(p);
+ NTOHS(dnslen);
} else {
offset += len;
continue;
@@ -991,9 +997,7 @@ axfr_connection(int so, char *address, int is_ipv6, dd
HTONS(odh->additional);
}
- tmp = (u_int16_t *)reply;
- *tmp = htons(outlen);
-
+ pack16(reply, htons(outlen));
len = send(so, reply, outlen + 2, 0);
if (len <= 0) {
goto drop;
@@ -1087,8 +1091,7 @@ axfr_connection(int so, char *address, int is_ipv6, dd
*/
/* XXX */
if (outlen > 60000) {
- tmp = (u_int16_t *)reply;
- *tmp = htons(outlen);
+ pack16(reply, htons(outlen));
/* set the rrcount in there */
@@ -1112,8 +1115,7 @@ axfr_connection(int so, char *address, int is_ipv6, dd
envelopcount++;
- tmp = (u_int16_t *)reply;
- *tmp = htons(outlen);
+ pack16(reply, htons(outlen));
}
len = send(so, reply, outlen + 2, 0);
@@ -1140,8 +1142,7 @@ axfr_connection(int so, char *address, int is_ipv6, dd
outlen = build_soa(db, (reply + 2), outlen, soa, question);
rrcount++;
- tmp = (u_int16_t *)reply;
- *tmp = htons(outlen);
+ pack16(reply, htons(outlen));
/* set the rrcount in there */
@@ -1158,8 +1159,7 @@ axfr_connection(int so, char *address, int is_ipv6, dd
outlen = additional_tsig(question, (reply + 2), 65000, outlen, 0, envelopcount, tsigctx);
odh->additional = htons(1);
- tmp = (u_int16_t *)reply;
- *tmp = htons(outlen);
+ pack16(reply, htons(outlen));
HMAC_CTX_free(tsigctx);
}
@@ -1239,7 +1239,8 @@ build_header(ddDB *db, char *reply, char *buf, struct
SET_DNS_REPLY(odh);
SET_DNS_AUTHORITATIVE(odh);
- NTOHS(odh->query);
+ /* XXX */
+ HTONS(odh->query);
odh->question = htons(1);
odh->answer = htons(answercount);
@@ -1264,7 +1265,6 @@ build_soa(ddDB *db, char *reply, int offset, struct rb
int labellen;
int tmplen;
- u_int32_t *soa_val;
struct answer {
char name[2];
@@ -1339,36 +1339,31 @@ build_soa(ddDB *db, char *reply, int offset, struct rb
/* XXX server error reply? */
return (offset);
}
- soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(((struct soa *)rrp->rdata)->serial);
+ pack32(&reply[offset], htonl(((struct soa *)rrp->rdata)->serial));
offset += sizeof(u_int32_t);
if ((offset + sizeof(u_int32_t)) >= 65535 ) {
return (offset);
}
- soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(((struct soa *)rrp->rdata)->refresh);
+ pack32(&reply[offset], htonl(((struct soa *)rrp->rdata)->refresh));
offset += sizeof(u_int32_t);
if ((offset + sizeof(u_int32_t)) >= 65535 ) {
return (offset);
}
- soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(((struct soa *)rrp->rdata)->retry);
+ pack32(&reply[offset], htonl(((struct soa *)rrp->rdata)->retry));
offset += sizeof(u_int32_t);
if ((offset + sizeof(u_int32_t)) >= 65535 ) {
return (offset);
}
- soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(((struct soa *)rrp->rdata)->expire);
+ pack32(&reply[offset], htonl(((struct soa *)rrp->rdata)->expire));
offset += sizeof(u_int32_t);
if ((offset + sizeof(u_int32_t)) > 65535 ) {
return (offset);
}
- soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(((struct soa *)rrp->rdata)->minttl);
+ pack32(&reply[offset], htonl(((struct soa *)rrp->rdata)->minttl));
offset += sizeof(u_int32_t);
answer->rdlength = htons(&reply[offset] - &answer->rdata);
blob - a566b2cb178ceab4a9cc2597edc4478cdcffd623
blob + 82d58c65a31ba027b426b353e14593c8689d05d8
--- dddctl.c
+++ dddctl.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: dddctl.c,v 1.90 2019/11/27 09:29:37 pjp Exp $
+ * $Id: dddctl.c,v 1.91 2019/12/03 18:21:40 pjp Exp $
*/
#include <sys/param.h>
@@ -178,10 +178,6 @@ int sign_ds(ddDB *, char *, struct keysentry *, int, s
int sign(int, char *, int, struct keysentry *, char *, int *);
int create_ds(ddDB *, char *, struct keysentry *);
u_int keytag(u_char *key, u_int keysize);
-void pack(char *, char *, int);
-void pack32(char *, u_int32_t);
-void pack16(char *, u_int16_t);
-void pack8(char *, u_int8_t);
void free_private_key(struct keysentry *);
RSA * get_private_key_rsa(struct keysentry *);
EC_KEY *get_private_key_ec(struct keysentry *);
@@ -305,6 +301,14 @@ u_int64_t expiredon, signedon;
/* externs */
+extern uint32_t unpack32(char *);
+extern uint16_t unpack16(char *);
+extern void unpack(char *, char *, int);
+
+extern void pack(char *, char *, int);
+extern void pack32(char *, u_int32_t);
+extern void pack16(char *, u_int16_t);
+extern void pack8(char *, u_int8_t);
extern int fill_dnskey(char *, char *, u_int32_t, u_int16_t, u_int8_t, u_int8_t, char *);
extern int fill_rrsig(char *, char *, u_int32_t, char *, u_int8_t, u_int8_t, u_int32_t, u_int64_t, u_int64_t, u_int16_t, char *, char *);
extern int fill_nsec3param(char *, char *, u_int32_t, u_int8_t, u_int8_t, u_int16_t, char *);
@@ -5464,42 +5468,8 @@ keytag(u_char *key, u_int keysize)
}
-/* pack functions */
void
-pack32(char *buf, u_int32_t value)
-{
- u_int32_t *p;
-
- p = (u_int32_t *)buf;
- *p = value;
-}
-
-void
-pack16(char *buf, u_int16_t value)
-{
- u_int16_t *p;
-
- p = (u_int16_t *)buf;
- *p = value;
-}
-
-void
-pack8(char *buf, u_int8_t value)
-{
- u_int8_t *p;
-
- p = (u_int8_t *)buf;
- *p = value;
-}
-
-void
-pack(char *buf, char *input, int len)
-{
- memcpy(buf, input, len);
-}
-
-void
free_private_key(struct keysentry *kn)
{
if (kn->algorithm < 13) {
@@ -6623,8 +6593,8 @@ lookup_name(FILE *f, int so, char *zonename, u_int16_t
u_char *end, *estart;
int totallen, zonelen, rrlen;
int replysize = 0;
- u_int16_t *class, *type, *tcpsize;
- u_int16_t *plen;
+ u_int16_t class = 0, type = 0, tcpsize;
+ u_int16_t plen;
u_int16_t tcplen;
if (format & TCP_FORMAT)
@@ -6636,7 +6606,7 @@ lookup_name(FILE *f, int so, char *zonename, u_int16_t
memset(&query, 0, sizeof(query));
if (format & TCP_FORMAT) {
- tcpsize = (u_int16_t *)&query[0];
+ tcpsize = unpack16(&query[0]);
wh = (struct whole_header *)&query[2];
} else
wh = (struct whole_header *)&query[0];
@@ -6671,12 +6641,12 @@ lookup_name(FILE *f, int so, char *zonename, u_int16_t
memcpy(p, name, len);
totallen += len;
- type = (u_int16_t *)&query[totallen];
- *type = htons(myrrtype);
+ type = htons(myrrtype);
+ pack16(&query[totallen], type);
totallen += sizeof(u_int16_t);
- class = (u_int16_t *)&query[totallen];
- *class = htons(DNS_CLASS_IN);
+ class = htons(DNS_CLASS_IN);
+ pack16(&query[totallen], class);
totallen += sizeof(u_int16_t);
/* attach EDNS0 */
@@ -6696,7 +6666,7 @@ lookup_name(FILE *f, int so, char *zonename, u_int16_t
totallen += (sizeof(struct dns_optrr));
if (format & TCP_FORMAT)
- *tcpsize = htons(totallen - 2);
+ tcpsize = htons(totallen - 2);
if (send(so, query, totallen, 0) < 0) {
return -1;
@@ -6716,8 +6686,8 @@ lookup_name(FILE *f, int so, char *zonename, u_int16_t
return -1;
}
- plen = (u_int16_t *)reply;
- tcplen = ntohs(*plen);
+ plen = unpack16(reply);
+ tcplen = ntohs(plen);
if ((len = recv(so, reply, tcplen + 2, MSG_WAITALL)) < 0) {
perror("recv");
@@ -6787,7 +6757,7 @@ lookup_name(FILE *f, int so, char *zonename, u_int16_t
return -1;
}
- if (q->hdr->qclass != *class || q->hdr->qtype != *type) {
+ if (q->hdr->qclass != class || q->hdr->qtype != type) {
fprintf(stderr, "wrong class or type\n");
return -1;
}
blob - ad3284969ef3036f2a51854748f2f66cbac863ef
blob + 488fbb100a23eb6a8fd14d840bbaabb343cc8dd5
--- delphinusdnsd.c
+++ delphinusdnsd.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: delphinusdnsd.c,v 1.87 2019/11/25 15:22:11 pjp Exp $
+ * $Id: delphinusdnsd.c,v 1.88 2019/12/03 18:21:40 pjp Exp $
*/
@@ -95,6 +95,14 @@
/* prototypes */
+extern void pack(char *, char *, int);
+extern void pack32(char *, u_int32_t);
+extern void pack16(char *, u_int16_t);
+extern void pack8(char *, u_int8_t);
+extern uint32_t unpack32(char *);
+extern uint16_t unpack16(char *);
+extern void unpack(char *, char *, int);
+
extern void add_rrlimit(int, u_int16_t *, int, char *);
extern void axfrloop(int *, int, char **, ddDB *, struct imsgbuf *);
extern void replicantloop(ddDB *, struct imsgbuf *, struct imsgbuf *);
@@ -1125,7 +1133,6 @@ compress_label(u_char *buf, u_int16_t offset, int labe
u_int i, j;
u_int checklen;
- u_int16_t *compressor;
u_char *p, *e;
u_char *compressmark;
@@ -1350,13 +1357,7 @@ out:
/* take off our compress length */
offset -= checklen;
/* write compressed label */
- compressor = (u_int16_t *)&buf[offset];
-
- *compressor = (compressmark - &buf[0]);
- *compressor |= 0xc000;
-
- /* network byte order */
- HTONS(*compressor);
+ pack16(&buf[offset], htons((compressmark - &buf[0]) | 0xc000));
offset += sizeof(u_int16_t);
blob - f1e80a3bdf00ecd93eeaad3fde845f142385006e
blob + 37eecfef16226142d2451e8fc6b6a79fc5460af3
--- raxfr.c
+++ raxfr.c
@@ -26,7 +26,7 @@
*
*/
/*
- * $Id: raxfr.c,v 1.40 2019/11/27 12:50:25 pjp Exp $
+ * $Id: raxfr.c,v 1.41 2019/12/03 18:21:40 pjp Exp $
*/
#include <sys/types.h>
@@ -146,7 +146,11 @@ extern int lookup_axfr(FILE *, in
extern int find_tsig_key(char *, int, char *, int);
extern int tsig_pseudoheader(char *, uint16_t, time_t, HMAC_CTX *);
+extern uint32_t unpack32(char *);
+extern uint16_t unpack16(char *);
+extern void unpack(char *, char *, int);
+
/* The following alias helps with bounds checking all input, needed! */
#define BOUNDS_CHECK(cur, begin, rdlen, end) do { \
@@ -186,8 +190,8 @@ raxfr_peek(FILE *f, u_char *p, u_char *estart, u_char
char *humanname;
u_char expand[256];
u_char *q = p;
- u_int16_t *rtype, *rclass, *rdtmp;
- u_int32_t *rttl;
+ u_int16_t rtype, rclass, rdtmp;
+ u_int32_t rttl;
int elen = 0;
int max = sizeof(expand);
char *hightype;
@@ -205,29 +209,29 @@ raxfr_peek(FILE *f, u_char *p, u_char *estart, u_char
if ((q + 2) > end)
return -1;
- rtype = (u_int16_t *)q;
+ rtype = unpack16(q);
q += 2;
if ((q + 2) > end)
return -1;
- rclass = (u_int16_t *)q;
+ rclass = unpack16(q);
q += 2;
if ((q + 4) > end)
return -1;
- rttl = (u_int32_t *)q;
+ rttl = unpack32(q);
q += 4;
if ((q + 2) > end)
return -1;
- rdtmp = (u_int16_t *)q;
- *rdlen = ntohs(*rdtmp);
+ rdtmp = unpack16(q);
+ *rdlen = ntohs(rdtmp);
q += 2;
- *rrtype = ntohs(*rtype);
+ *rrtype = ntohs(rtype);
if (ctx != NULL) {
if (*rrtype != DNS_TYPE_TSIG) {
@@ -243,7 +247,7 @@ raxfr_peek(FILE *f, u_char *p, u_char *estart, u_char
return -1;
}
- hightype = get_dns_type(ntohs(*rtype), 0);
+ hightype = get_dns_type(ntohs(rtype), 0);
for (i = 0; i < strlen(hightype); i++)
hightype[i] = tolower(hightype[i]);
@@ -252,20 +256,20 @@ raxfr_peek(FILE *f, u_char *p, u_char *estart, u_char
if (soacount < 1) {
if ((format & INDENT_FORMAT))
- fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(*rttl));
+ fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
else if ((format & ZONE_FORMAT)) {
- fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(*rttl));
+ fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
} else
- fprintf(f, "%s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(*rttl));
+ fprintf(f, "%s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
} else {
if ((format & INDENT_FORMAT))
- fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(*rttl));
+ fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
else if ((format & ZONE_FORMAT)) {
if (*rrtype != DNS_TYPE_SOA) {
- fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(*rttl));
+ fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
}
} else {
- fprintf(f, "%s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(*rttl));
+ fprintf(f, "%s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
}
}
}
@@ -283,20 +287,20 @@ u_int16_t
raxfr_skip(FILE *f, u_char *p, u_char *estart)
{
u_char *q;
- u_int16_t *rdlen;
+ u_int16_t rdlen;
if ((q = p - 2) <= estart)
return 0;
- rdlen = (u_int16_t *)q;
+ rdlen = unpack16(q);
- return ((u_int16_t)ntohs(*rdlen));
+ return ((u_int16_t)ntohs(rdlen));
}
int
raxfr_soa(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, int soacount, u_int32_t format, u_int16_t rdlen, HMAC_CTX *ctx)
{
- u_int32_t *rvalue;
+ u_int32_t rvalue;
char *save, *humanname;
u_char *q = p;
u_char expand[256];
@@ -367,24 +371,24 @@ raxfr_soa(FILE *f, u_char *p, u_char *estart, u_char *
free(humanname);
BOUNDS_CHECK((q + 4), p, rdlen, end);
- rvalue = (u_int32_t *)q;
- mysoa->serial = *rvalue;
+ rvalue = unpack32(q);
+ mysoa->serial = rvalue;
q += sizeof(u_int32_t);
BOUNDS_CHECK((q + 4), p, rdlen, end);
- rvalue = (u_int32_t *)q;
- mysoa->refresh = *rvalue;
+ rvalue = unpack32(q);
+ mysoa->refresh = rvalue;
q += sizeof(u_int32_t);
BOUNDS_CHECK((q + 4), p, rdlen, end);
- rvalue = (u_int32_t *)q;
- mysoa->retry = *rvalue;
+ rvalue = unpack32(q);
+ mysoa->retry = rvalue;
q += sizeof(u_int32_t);
BOUNDS_CHECK((q + 4), p, rdlen, end);
- rvalue = (u_int32_t *)q;
- mysoa->expire = *rvalue;
+ rvalue = unpack32(q);
+ mysoa->expire = rvalue;
q += sizeof(u_int32_t);
BOUNDS_CHECK((q + 4), p, rdlen, end);
- rvalue = (u_int32_t *)q;
- mysoa->minttl = *rvalue;
+ rvalue = unpack32(q);
+ mysoa->minttl = rvalue;
q += sizeof(u_int32_t);
if (soacount < soalimit) {
@@ -410,34 +414,34 @@ raxfr_rrsig(FILE *f, u_char *p, u_char *estart, u_char
u_char expand[256];
int max = sizeof(expand);
int elen = 0;
- u_int16_t *tmp;
- u_int32_t *tmp4;
+ u_int16_t tmp;
+ u_int32_t tmp4;
int len;
u_char *b;
BOUNDS_CHECK((q + 2), p, rdlen, end);
- tmp = (u_int16_t *)q;
- rs.type_covered = ntohs(*tmp);
+ tmp = unpack16(q);
+ rs.type_covered = ntohs(tmp);
q += 2;
BOUNDS_CHECK((q + 1), p, rdlen, end);
rs.algorithm = *q++;
BOUNDS_CHECK((q + 1), p, rdlen, end);
rs.labels = *q++;
BOUNDS_CHECK((q + 4), p, rdlen, end);
- tmp4 = (u_int32_t *)q;
- rs.original_ttl = ntohl(*tmp4);
+ tmp4 = unpack32(q);
+ rs.original_ttl = ntohl(tmp4);
q += 4;
BOUNDS_CHECK((q + 4), p, rdlen, end);
- tmp4 = (u_int32_t *)q;
- rs.signature_expiration = ntohl(*tmp4);
+ tmp4 = unpack32(q);
+ rs.signature_expiration = ntohl(tmp4);
q += 4;
BOUNDS_CHECK((q + 4), p, rdlen, end);
- tmp4 = (u_int32_t *)q;
- rs.signature_inception = ntohl(*tmp4);
+ tmp4 = unpack32(q);
+ rs.signature_inception = ntohl(tmp4);
q += 4;
BOUNDS_CHECK((q + 2), p, rdlen, end);
- tmp = (u_int16_t *)q;
- rs.key_tag = ntohs(*tmp);
+ tmp = unpack16(q);
+ rs.key_tag = ntohs(tmp);
q += 2;
memset(&expand, 0, sizeof(expand));
@@ -499,12 +503,12 @@ int
raxfr_ds(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
struct ds d;
- u_int16_t *tmpshort;
+ u_int16_t tmpshort;
u_char *q = p;
BOUNDS_CHECK((p + 2), q, rdlen, end);
- tmpshort = (u_int16_t *)p;
- d.key_tag = ntohs(*tmpshort);
+ tmpshort = unpack16(p);
+ d.key_tag = ntohs(tmpshort);
p += 2;
BOUNDS_CHECK((p + 1), q, rdlen, end);
d.algorithm = *p++;
@@ -569,14 +573,14 @@ int
raxfr_dnskey(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
struct dnskey dk;
- u_int16_t *tmpshort;
+ u_int16_t tmpshort;
char *b;
u_char *q = p;
int len;
BOUNDS_CHECK((p + 2), q, rdlen, end);
- tmpshort = (u_int16_t *)p;
- dk.flags = ntohs(*tmpshort);
+ tmpshort = unpack16(p);
+ dk.flags = ntohs(tmpshort);
p += 2;
BOUNDS_CHECK((p + 1), q, rdlen, end);
dk.protocol = *p++;
@@ -622,7 +626,7 @@ raxfr_dnskey(FILE *f, u_char *p, u_char *estart, u_cha
int
raxfr_mx(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
- u_int16_t *mxpriority;
+ u_int16_t mxpriority;
char *save, *humanname;
u_char *q = p;
u_char expand[256];
@@ -630,10 +634,10 @@ raxfr_mx(FILE *f, u_char *p, u_char *estart, u_char *e
int elen = 0;
BOUNDS_CHECK((q + 2), p, rdlen, end);
- mxpriority = (u_int16_t *)q;
+ mxpriority = unpack16(q);
if (f != NULL)
- fprintf(f, "%u,", ntohs(*mxpriority));
+ fprintf(f, "%u,", ntohs(mxpriority));
q += 2;
@@ -676,7 +680,7 @@ int
raxfr_nsec3(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
struct nsec3 n;
- u_int16_t *iter;
+ u_int16_t iter;
u_char *brr = p; /* begin of rd record :-) */
BOUNDS_CHECK((p + 1), brr, rdlen, end);
@@ -685,8 +689,8 @@ raxfr_nsec3(FILE *f, u_char *p, u_char *estart, u_char
n.flags = *p++;
BOUNDS_CHECK((p + 2), brr, rdlen, end);
- iter = (u_int16_t *)p;
- n.iterations = ntohs(*iter);
+ iter = unpack16(p);
+ n.iterations = ntohs(iter);
p += 2;
BOUNDS_CHECK((p + 1), brr, rdlen, end);
@@ -732,7 +736,7 @@ int
raxfr_nsec3param(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
struct nsec3param np;
- u_int16_t *iter;
+ u_int16_t iter;
char *hex;
u_char *q = p;
@@ -741,8 +745,8 @@ raxfr_nsec3param(FILE *f, u_char *p, u_char *estart, u
BOUNDS_CHECK((p + 1), q, rdlen, end);
np.flags = *p++;
BOUNDS_CHECK((p + 2), q, rdlen, end);
- iter = (u_int16_t *)p;
- np.iterations = ntohs(*iter);
+ iter = unpack16(p);
+ np.iterations = ntohs(iter);
p += 2;
BOUNDS_CHECK((p + 1), q, rdlen, end);
np.saltlen = *p++;
@@ -846,17 +850,17 @@ int
raxfr_aaaa(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
char buf[INET6_ADDRSTRLEN];
- struct in6_addr *ia;
+ struct in6_addr ia;
u_char *q = p;
- BOUNDS_CHECK((p + sizeof(*ia)), q, rdlen, end);
- ia = (struct in6_addr *)p;
- inet_ntop(AF_INET6, ia, buf, sizeof(buf));
+ BOUNDS_CHECK((p + sizeof(ia)), q, rdlen, end);
+ unpack((char *)&ia, p, sizeof(struct in6_addr));
+ inet_ntop(AF_INET6, &ia, buf, sizeof(buf));
if (f != NULL)
fprintf(f, "%s\n", buf);
- p += sizeof(*ia);
+ p += sizeof(ia);
if (ctx != NULL)
HMAC_Update(ctx, q, p - q);
@@ -868,18 +872,18 @@ int
raxfr_a(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
char buf[INET_ADDRSTRLEN];
- struct in_addr *ia;
+ struct in_addr ia;
u_char *q = p;
- BOUNDS_CHECK((p + sizeof(*ia)), q, rdlen, end);
- ia = (struct in_addr *)p;
+ BOUNDS_CHECK((p + sizeof(ia)), q, rdlen, end);
+ ia.s_addr = unpack32(p);
- inet_ntop(AF_INET, ia, buf, sizeof(buf));
+ inet_ntop(AF_INET, &ia, buf, sizeof(buf));
if (f != NULL)
fprintf(f, "%s\n", buf);
- p += sizeof(*ia);
+ p += sizeof(ia);
if (ctx != NULL)
HMAC_Update(ctx, q, p - q);
@@ -925,7 +929,7 @@ raxfr_tlsa(FILE *f, u_char *p, u_char *estart, u_char
int
raxfr_srv(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
- u_int16_t *tmp16;
+ u_int16_t tmp16;
struct srv s;
char *save, *humanname;
u_char *q = p;
@@ -934,16 +938,16 @@ raxfr_srv(FILE *f, u_char *p, u_char *estart, u_char *
int elen = 0;
BOUNDS_CHECK((q + 2), p, rdlen, end);
- tmp16 = (u_int16_t *)q;
- s.priority = ntohs(*tmp16);
+ tmp16 = unpack16(q);
+ s.priority = ntohs(tmp16);
q += 2;
BOUNDS_CHECK((q + 2), p, rdlen, end);
- tmp16 = (u_int16_t *)q;
- s.weight = ntohs(*tmp16);
+ tmp16 = unpack16(q);
+ s.weight = ntohs(tmp16);
q += 2;
BOUNDS_CHECK((q + 2), p, rdlen, end);
- tmp16 = (u_int16_t *)q;
- s.port = ntohs(*tmp16);
+ tmp16 = unpack16(q);
+ s.port = ntohs(tmp16);
q += 2;
memset(&expand, 0, sizeof(expand));
@@ -979,7 +983,7 @@ raxfr_srv(FILE *f, u_char *p, u_char *estart, u_char *
int
raxfr_naptr(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
{
- u_int16_t *tmp16;
+ u_int16_t tmp16;
struct naptr n;
char *save, *humanname;
u_char *q = p;
@@ -989,12 +993,12 @@ raxfr_naptr(FILE *f, u_char *p, u_char *estart, u_char
int len, i;
BOUNDS_CHECK((q + 2), p, rdlen, end);
- tmp16 = (u_int16_t *)q;
- n.order = ntohs(*tmp16);
+ tmp16 = unpack16(q);
+ n.order = ntohs(tmp16);
q += 2;
BOUNDS_CHECK((q + 2), p, rdlen, end);
- tmp16 = (u_int16_t *)q;
- n.preference = ntohs(*tmp16);
+ tmp16 = unpack16(q);
+ n.preference = ntohs(tmp16);
q += 2;
if (f != NULL) {
@@ -1081,8 +1085,8 @@ raxfr_tsig(FILE *f, u_char *p, u_char *estart, u_char
char *otherdata;
u_char expand[256];
u_char *q = p;
- u_int16_t *rtype, *rclass, *origid, *tsigerror, *otherlen;
- u_int32_t *rttl;
+ u_int16_t rtype, rclass, origid, tsigerror, otherlen;
+ u_int32_t rttl;
int rlen, rrlen = -1;
int elen = 0;
int max = sizeof(expand);
@@ -1112,28 +1116,28 @@ raxfr_tsig(FILE *f, u_char *p, u_char *estart, u_char
if ((q + 2) > end)
goto out;
- rtype = (u_int16_t *)q;
+ rtype = unpack16(q);
q += 2;
- if (ntohs(*rtype) != DNS_TYPE_TSIG)
+ if (ntohs(rtype) != DNS_TYPE_TSIG)
goto out;
if ((q + 2) > end)
goto out;
- rclass = (u_int16_t *)q;
+ rclass = unpack16(q);
q += 2;
- if (ntohs(*rclass) != DNS_CLASS_ANY)
+ if (ntohs(rclass) != DNS_CLASS_ANY)
goto out;
if ((q + 4) > end)
goto out;
- rttl = (u_int32_t *)q;
+ rttl = unpack32(q);
q += 4;
- if (*rttl != 0)
+ if (rttl != 0)
goto out;
/* skip rdlen because raxfr_peek already got it */
@@ -1178,23 +1182,23 @@ raxfr_tsig(FILE *f, u_char *p, u_char *estart, u_char
if ((q + 2) > end)
goto out;
- origid = (uint16_t *)q;
+ origid = unpack16(q);
q += 2;
if ((q + 2) > end)
goto out;
- tsigerror = (uint16_t *)q;
+ tsigerror = unpack16(q);
q += 2;
if ((q + 2) > end)
goto out;
- otherlen = (uint16_t *)q;
+ otherlen = unpack16(q);
q += 2;
otherdata = q;
- q += ntohs(*otherlen);
+ q += ntohs(otherlen);
if ((q - estart) != (rdlen + rlen)) {
goto out;
@@ -1205,14 +1209,14 @@ raxfr_tsig(FILE *f, u_char *p, u_char *estart, u_char
if (standardanswer) {
/* dns message */
HMAC_Update(ctx, rawkeyname, rawkeynamelen);
- HMAC_Update(ctx, (char *)rclass, 2);
- HMAC_Update(ctx, (char *)rttl, 4);
+ HMAC_Update(ctx, (char *)&rclass, 2);
+ HMAC_Update(ctx, (char *)&rttl, 4);
HMAC_Update(ctx, rawalgname, rawalgnamelen);
HMAC_Update(ctx, (char *)&sdt->timefudge, 8);
- HMAC_Update(ctx, (char *)tsigerror, 2);
- HMAC_Update(ctx, (char *)otherlen, 2);
- if (ntohs(*otherlen))
- HMAC_Update(ctx, otherdata, ntohs(*otherlen));
+ HMAC_Update(ctx, (char *)&tsigerror, 2);
+ HMAC_Update(ctx, (char *)&otherlen, 2);
+ if (ntohs(otherlen))
+ HMAC_Update(ctx, otherdata, ntohs(otherlen));
} else {
HMAC_Update(ctx, (char *)&sdt->timefudge, 8);
blob - 4f2babe43709ae71dcc313466acb90c57b9ccecb
blob + cdeccb30d925d10a4e3d322f5e8a45e455adeef5
--- reply.c
+++ reply.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: reply.c,v 1.95 2019/11/28 07:55:20 pjp Exp $
+ * $Id: reply.c,v 1.96 2019/12/03 18:21:40 pjp Exp $
*/
#include <sys/types.h>
@@ -70,6 +70,14 @@
/* prototypes */
+extern void pack(char *, char *, int);
+extern void pack32(char *, u_int32_t);
+extern void pack16(char *, u_int16_t);
+extern void pack8(char *, u_int8_t);
+extern uint32_t unpack32(char *);
+extern uint16_t unpack16(char *);
+extern void unpack(char *, char *, int);
+
extern int checklabel(ddDB *, struct rbtree *, struct rbtree *, struct question *);
extern int additional_nsec3(char *, int, int, struct rbtree *, char *, int, int);
extern int additional_a(char *, int, struct rbtree *, char *, int, int, int *);
@@ -310,15 +318,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -521,15 +526,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -745,15 +747,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -940,15 +939,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -1137,15 +1133,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -1348,15 +1341,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -1500,15 +1490,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -1673,15 +1660,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -1710,7 +1694,6 @@ reply_mx(struct sreply *sreply, ddDB *db)
char *reply = sreply->replybuf;
struct dns_header *odh;
int mx_count;
- u_int16_t *plen;
char *name;
u_int16_t outlen = 0;
u_int16_t namelen;
@@ -2014,9 +1997,7 @@ out:
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
@@ -2043,7 +2024,6 @@ reply_ns(struct sreply *sreply, ddDB *db)
struct dns_header *odh;
int tmplen = 0;
int ns_count;
- u_int16_t *plen;
char *name;
u_int16_t outlen = 0;
u_int16_t namelen;
@@ -2409,9 +2389,7 @@ out:
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
@@ -2446,7 +2424,6 @@ reply_cname(struct sreply *sreply, ddDB *db)
int labellen;
char *label, *plabel;
int addcount;
- u_int16_t *plen;
struct answer {
char name[2];
@@ -2725,9 +2702,7 @@ out:
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -2909,15 +2884,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -3168,15 +3140,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -3368,15 +3337,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -3497,15 +3463,12 @@ reply_version(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -3533,7 +3496,6 @@ reply_tlsa(struct sreply *sreply, ddDB *db)
char *reply = sreply->replybuf;
struct dns_header *odh;
int tlsa_count;
- u_int16_t *plen;
u_int16_t outlen;
struct answer {
@@ -3693,9 +3655,7 @@ out:
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
@@ -3723,7 +3683,6 @@ reply_sshfp(struct sreply *sreply, ddDB *db)
char *reply = sreply->replybuf;
struct dns_header *odh;
int sshfp_count;
- u_int16_t *plen;
u_int16_t outlen;
struct answer {
@@ -3881,9 +3840,7 @@ out:
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
@@ -3911,7 +3868,6 @@ reply_naptr(struct sreply *sreply, ddDB *db)
char *reply = sreply->replybuf;
struct dns_header *odh;
int naptr_count;
- u_int16_t *plen;
char *name;
u_int16_t outlen;
u_int16_t namelen;
@@ -4104,9 +4060,7 @@ out:
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
@@ -4134,7 +4088,6 @@ reply_srv(struct sreply *sreply, ddDB *db)
char *reply = sreply->replybuf;
struct dns_header *odh;
int srv_count;
- u_int16_t *plen;
char *name;
u_int16_t outlen;
u_int16_t namelen;
@@ -4298,9 +4251,7 @@ out:
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
@@ -4363,15 +4314,12 @@ reply_notimpl(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -4471,15 +4419,12 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(len + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(len);
-
+ pack16(tmpbuf, htons(len));
memcpy(&tmpbuf[2], reply, len);
if ((retlen = send(so, tmpbuf, len + 2, 0)) < 0) {
@@ -4768,15 +4713,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -4849,15 +4791,12 @@ reply_refused(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -4932,15 +4871,12 @@ reply_notauth(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -5016,15 +4952,12 @@ reply_notify(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -5084,15 +5017,12 @@ reply_fmterror(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -5121,7 +5051,6 @@ reply_noerror(struct sreply *sreply, ddDB *db)
struct dns_header *odh;
u_int16_t outlen;
char *p;
- u_int32_t *soa_val;
int i, tmplen;
int labellen;
char *label, *plabel;
@@ -5192,15 +5121,12 @@ reply_noerror(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(len + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(len);
-
+ pack16(tmpbuf, htons(len));
memcpy(&tmpbuf[2], reply, len);
if ((retlen = send(so, tmpbuf, len + 2, 0)) < 0) {
@@ -5310,36 +5236,31 @@ reply_noerror(struct sreply *sreply, ddDB *db)
/* XXX server error reply? */
return (retlen);
}
- soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(((struct soa *)rrp->rdata)->serial);
+ pack32(&reply[outlen], htonl(((struct soa *)rrp->rdata)->serial));
outlen += sizeof(u_int32_t);
if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
- soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(((struct soa *)rrp->rdata)->refresh);
+ pack32(&reply[outlen], htonl(((struct soa *)rrp->rdata)->refresh));
outlen += sizeof(u_int32_t);
if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
- soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(((struct soa *)rrp->rdata)->retry);
+ pack32(&reply[outlen], htonl(((struct soa *)rrp->rdata)->retry));
outlen += sizeof(u_int32_t);
if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
- soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(((struct soa *)rrp->rdata)->expire);
+ pack32(&reply[outlen], htonl(((struct soa *)rrp->rdata)->expire));
outlen += sizeof(u_int32_t);
if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
- soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(((struct soa *)rrp->rdata)->minttl);
+ pack32(&reply[outlen], htonl(((struct soa *)rrp->rdata)->minttl));
outlen += sizeof(u_int32_t);
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
@@ -5422,15 +5343,12 @@ out:
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -5532,15 +5450,12 @@ reply_any(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
@@ -6705,15 +6620,12 @@ reply_badvers(struct sreply *sreply, ddDB *db)
if (istcp) {
char *tmpbuf;
- u_int16_t *plen;
tmpbuf = malloc(outlen + 2);
if (tmpbuf == 0) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
}
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
+ pack16(tmpbuf, htons(outlen));
memcpy(&tmpbuf[2], reply, outlen);
if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
blob - bb2cd9b8f89a9daf5f18673402bb0d05db393197
blob + 7be4e97ad859fd40f213c844612146f92bb230de
--- util.c
+++ util.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: util.c,v 1.54 2019/11/19 16:58:41 pjp Exp $
+ * $Id: util.c,v 1.55 2019/12/03 18:21:40 pjp Exp $
*/
#include <sys/types.h>
@@ -83,6 +83,14 @@
/* prototypes */
+void pack(char *, char *, int);
+void pack32(char *, u_int32_t);
+void pack16(char *, u_int16_t);
+void pack8(char *, u_int8_t);
+uint32_t unpack32(char *);
+uint16_t unpack16(char *);
+void unpack(char *, char *, int);
+
int label_count(char *);
char * dns_label(char *, int *);
void slave_shutdown(void);
@@ -914,12 +922,13 @@ build_question(char *buf, int len, int additional, cha
char pseudo_packet[4096]; /* for tsig */
u_int rollback, i;
u_int namelen = 0;
- u_int16_t *qtype, *qclass;
+ u_int16_t qtype, qclass;
u_int32_t ttl;
u_int64_t timefudge;
int num_label;
char *p, *end_name = NULL;
+ char *o;
struct dns_tsigrr *tsigrr = NULL;
struct dns_optrr *opt = NULL;
@@ -1064,8 +1073,8 @@ build_question(char *buf, int len, int additional, cha
/* in IXFR an additional SOA entry is tacked on, we want to skip this */
do {
- u_int16_t *val16;
- u_int32_t *val32;
+ u_int16_t val16;
+ u_int32_t val32;
char *pb = NULL;
char expand[DNS_MAXNAME + 1];
int elen;
@@ -1087,31 +1096,36 @@ build_question(char *buf, int len, int additional, cha
}
/* type */
- val16 = (u_int16_t *)&buf[i];
- if (ntohs(*val16) != DNS_TYPE_SOA) {
+ o = &buf[i];
+ val16 = unpack16(o);
+ if (ntohs(val16) != DNS_TYPE_SOA) {
i = rollback;
break;
}
i += 2;
+ o += 2;
/* class */
- val16 = (u_int16_t *)&buf[i];
- if (ntohs(*val16) != DNS_CLASS_IN) {
+ val16 = unpack16(o);
+ if (ntohs(val16) != DNS_CLASS_IN) {
i = rollback;
break;
}
i += 2;
+ o += 2;
/* ttl */
- val32 = (u_int32_t *)&buf[i];
+ val32 = unpack32(o);
i += 4;
- val16 = (u_int16_t *)&buf[i];
+ o += 4;
+ val16 = unpack16(o);
i += 2;
- if (i + ntohs(*val16) > len) { /* rdlen of SOA */
+ if (i + ntohs(val16) > len) { /* rdlen of SOA */
i = rollback;
break;
}
- i += ntohs(*val16);
+ i += ntohs(val16);
+ o += ntohs(val16);
} while (0);
/* check for edns0 opt rr */
@@ -1158,9 +1172,9 @@ build_question(char *buf, int len, int additional, cha
} while (0);
/* check for TSIG rr */
do {
- u_int16_t *val16, *tsigerror, *tsigotherlen;
+ u_int16_t val16, tsigerror, tsigotherlen;
u_int16_t fudge;
- u_int32_t *val32;
+ u_int32_t val32;
int elen, tsignamelen;
char *pb;
char expand[DNS_MAXNAME + 1];
@@ -1207,12 +1221,14 @@ build_question(char *buf, int len, int additional, cha
}
/* type */
- val16 = (u_int16_t *)&buf[i];
- if (ntohs(*val16) != DNS_TYPE_TSIG) {
+ o = &buf[i];
+ val16 = unpack16(o);
+ if (ntohs(val16) != DNS_TYPE_TSIG) {
i = rollback;
break;
}
i += 2;
+ o += 2;
pseudolen2 = i;
q->tsig.have_tsig = 1;
@@ -1229,28 +1245,31 @@ build_question(char *buf, int len, int additional, cha
q->tsig.tsigerrorcode = DNS_BADKEY;
/* class */
- val16 = (u_int16_t *)&buf[i];
- if (ntohs(*val16) != DNS_CLASS_ANY) {
+ val16 = unpack16(o);
+ if (ntohs(val16) != DNS_CLASS_ANY) {
i = rollback;
break;
}
i += 2;
+ o += 2;
/* ttl */
- val32 = (u_int32_t *)&buf[i];
- if (ntohl(*val32) != 0) {
+ val32 = unpack32(o);
+ if (ntohl(val32) != 0) {
i = rollback;
break;
}
i += 4;
+ o += 4;
/* rdlen */
- val16 = (u_int16_t *)&buf[i];
- if (ntohs(*val16) != (len - (i + 2))) {
+ val16 = unpack16(o);
+ if (ntohs(val16) != (len - (i + 2))) {
i = rollback;
break;
}
i += 2;
+ o += 2;
pseudolen3 = i;
/* the algorithm name is parsed here */
@@ -1333,26 +1352,30 @@ build_question(char *buf, int len, int additional, cha
HTONS(hdr->additional);
/* origid */
- val16 = (u_int16_t *)&buf[i];
+ o = &buf[i];
+ val16 = unpack16(o);
i += 2;
- if (hdr->id != *val16)
- hdr->id = *val16;
- q->tsig.tsigorigid = *val16;
+ o += 2;
+ if (hdr->id != val16)
+ hdr->id = val16;
+ q->tsig.tsigorigid = val16;
/* error */
- tsigerror = (u_int16_t *)&buf[i];
+ tsigerror = unpack16(o);
i += 2;
+ o += 2;
/* other len */
- tsigotherlen = (u_int16_t *)&buf[i];
+ tsigotherlen = unpack16(o);
i += 2;
+ o += 2;
ppoffset = 0;
/* check if we have a request mac, this means it's an answer */
if (mac) {
- val16 = (u_int16_t *)&pseudo_packet[ppoffset];
- *val16 = htons(32); /* XXX magic number */
+ o = &pseudo_packet[ppoffset];
+ pack16(o, htons(32));
ppoffset += 2;
memcpy(&pseudo_packet[ppoffset], mac, 32);
@@ -1370,13 +1393,15 @@ build_question(char *buf, int len, int additional, cha
memcpy((char *)&pseudo_packet[ppoffset], (char *)&tsigrr->timefudge, 8);
ppoffset += 8;
- val16 = (u_int16_t *)&pseudo_packet[ppoffset];
- *val16 = *tsigerror;
+ o = &pseudo_packet[ppoffset];
+ pack16(o, tsigerror);
ppoffset += 2;
+ o += 2;
- val16 = (u_int16_t *)&pseudo_packet[ppoffset];
- *val16 = *tsigotherlen;
+ o = &pseudo_packet[ppoffset];
+ pack16(o, tsigotherlen);
ppoffset += 2;
+ o += 2;
memcpy(&pseudo_packet[ppoffset], &buf[i], len - i);
ppoffset += (len - i);
@@ -1433,17 +1458,19 @@ build_question(char *buf, int len, int additional, cha
/* parse type and class from the question */
- qtype = (u_int16_t *)(end_name + 1);
- qclass = (u_int16_t *)(end_name + sizeof(u_int16_t) + 1);
+ o = (end_name + 1);
+ qtype = unpack16(o);
+ o = (end_name + sizeof(uint16_t) + 1);
+ qclass = unpack16(o);
- memcpy((char *)&q->hdr->qtype, (char *)qtype, sizeof(u_int16_t));
- memcpy((char *)&q->hdr->qclass, (char *)qclass, sizeof(u_int16_t));
+ memcpy((char *)&q->hdr->qtype, (char *)&qtype, sizeof(u_int16_t));
+ memcpy((char *)&q->hdr->qclass, (char *)&qclass, sizeof(u_int16_t));
/* make note of whether recursion is desired */
q->rd = ((ntohs(hdr->query) & DNS_RECURSE) == DNS_RECURSE);
/* are we a notify packet? */
- if ((ntohs(*qtype) == DNS_TYPE_SOA) && (ntohs(*qclass) == DNS_CLASS_IN))
+ if ((ntohs(qtype) == DNS_TYPE_SOA) && (ntohs(qclass) == DNS_CLASS_IN))
q->notify = ((ntohs(hdr->query) & (DNS_NOTIFY | DNS_AUTH)) \
== (DNS_NOTIFY | DNS_AUTH));
else
@@ -1498,7 +1525,7 @@ expand_compression(u_char *p, u_char *estart, u_char *
{
u_short tlen;
u_char *save = NULL;
- u_int16_t *offset;
+ u_int16_t offset;
/* expand name */
while ((u_char)*p && p <= end) {
@@ -1508,13 +1535,13 @@ expand_compression(u_char *p, u_char *estart, u_char *
if (! save) {
save = p + 2;
}
- offset = (u_int16_t *)p;
+ offset = unpack16(p);
/* do not allow forwards jumping */
- if ((p - estart) <= (ntohs(*offset) & (~0xc000))) {
+ if ((p - estart) <= (ntohs(offset) & (~0xc000))) {
return NULL;
}
- p = (estart + (ntohs(*offset) & (~0xc000)));
+ p = (estart + (ntohs(offset) & (~0xc000)));
} else {
if (*elen + 1 >= max) {
return NULL;
@@ -1589,8 +1616,7 @@ tsig_pseudoheader(char *tsigkeyname, uint16_t fudge, t
int ppoffset = 0I;
int len;
- uint16_t *type;
- uint32_t *ttl;
+ char *p;
keyname = dns_label(tsigkeyname, &len);
if (keyname == NULL) {
@@ -1600,18 +1626,19 @@ tsig_pseudoheader(char *tsigkeyname, uint16_t fudge, t
/* name of key */
memcpy(&pseudo_packet, keyname, len);
ppoffset += len;
+ p = &pseudo_packet[len];
free(keyname);
/* class */
- type = (u_int16_t *) &pseudo_packet[ppoffset];
- *type = htons(DNS_CLASS_ANY);
+ pack16(p, htons(DNS_CLASS_ANY));
ppoffset += 2;
+ p += 2;
/* TTL */
- ttl = (u_int32_t *) &pseudo_packet[ppoffset];
- *ttl = htonl(0);
+ pack32(p, 0);
ppoffset += 4;
+ p += 4;
keyname = dns_label("hmac-sha256", &len);
if (keyname == NULL) {
@@ -1621,35 +1648,36 @@ tsig_pseudoheader(char *tsigkeyname, uint16_t fudge, t
/* alg name */
memcpy(&pseudo_packet[ppoffset], keyname, len);
ppoffset += len;
+ p += len;
free(keyname);
/* time 1 and 2 */
now = time(NULL);
- type = (u_int16_t *)&pseudo_packet[ppoffset];
- *type = htons((now >> 32) & 0xffff);
+ pack16(p, htons((now >> 32) & 0xffff));
ppoffset += 2;
+ p += 2;
- ttl = (u_int32_t *)&pseudo_packet[ppoffset];
- *ttl = htonl((now & 0xffffffff));
+ pack32(p, htonl((now & 0xffffffff)));
ppoffset += 4;
+ p += 4;
/* fudge */
- type = (u_int16_t *)&pseudo_packet[ppoffset];
- *type = htons(fudge);
+ pack16(p, htons(fudge));
ppoffset += 2;
+ p += 2;
/* error */
- type = (u_int16_t *)&pseudo_packet[ppoffset];
- *type = htons(0);
+ pack16(p, 0);
ppoffset += 2;
+ p += 2;
/* other len */
- type = (u_int16_t *)&pseudo_packet[ppoffset];
- *type = htons(0);
+ pack16(p, 0);
ppoffset += 2;
+ p += 2;
HMAC_Update(ctx, pseudo_packet, ppoffset);
@@ -1796,8 +1824,7 @@ lookup_axfr(FILE *f, int so, char *zonename, struct so
int elen = 0;
int segmentcount = 0;
int count = 0;
- u_int32_t *ttl;
- u_int16_t *class, *type, rdlen, *plen;
+ u_int16_t rdlen, *plen;
u_int16_t tcplen;
HMAC_CTX *ctx;
@@ -1837,14 +1864,15 @@ lookup_axfr(FILE *f, int so, char *zonename, struct so
memcpy(p, name, len);
totallen += len;
+ p += len;
- type = (u_int16_t *)&query[totallen];
- *type = htons(DNS_TYPE_AXFR);
+ pack16(p, htons(DNS_TYPE_AXFR));
totallen += sizeof(u_int16_t);
+ p += sizeof(u_int16_t);
- class = (u_int16_t *)&query[totallen];
- *class = htons(DNS_CLASS_IN);
+ pack16(p, htons(DNS_CLASS_IN));
totallen += sizeof(u_int16_t);
+ p += sizeof(u_int16_t);
/* we have a key, attach a TSIG payload */
if (tsigkey) {
@@ -1881,17 +1909,18 @@ lookup_axfr(FILE *f, int so, char *zonename, struct so
memcpy(&query[totallen], keyname, len);
totallen += len;
- type = (u_int16_t *)&query[totallen];
- *type = htons(DNS_TYPE_TSIG);
+ p = &query[totallen];
+ pack16(p, htons(DNS_TYPE_TSIG));
totallen += 2;
+ p += 2;
- class = (u_int16_t *)&query[totallen];
- *class = htons(DNS_CLASS_ANY);
+ pack16(p, htons(DNS_CLASS_ANY));
totallen += 2;
+ p += 2;
- ttl = (u_int32_t *)&query[totallen];
- *ttl = htonl(0);
+ pack32(p, htonl(0));
totallen += 4;
+ p += 4;
keyname = dns_label("hmac-sha256", &len);
if (keyname == NULL) {
@@ -1899,52 +1928,54 @@ lookup_axfr(FILE *f, int so, char *zonename, struct so
}
/* rdlen */
- type = (u_int16_t *)&query[totallen];
- *type = htons(len + 2 + 4 + 2 + 2 + 32 + 2 + 2 + 2);
+ pack16(p, htons(len + 2 + 4 + 2 + 2 + 32 + 2 + 2 + 2));
totallen += 2;
+ p += 2;
/* algorithm name */
memcpy(&query[totallen], keyname, len);
totallen += len;
+ p += len;
/* time 1 */
- type = (u_int16_t *)&query[totallen];
- *type = htons((now >> 32) & 0xffff);
+ pack16(p, htons((now >> 32) & 0xffff));
totallen += 2;
+ p += 2;
/* time 2 */
- ttl = (u_int32_t *)&query[totallen];
- *ttl = htonl((now & 0xffffffff));
+ pack32(p, htonl(now & 0xffffffff));
totallen += 4;
+ p += 4;
/* fudge */
- type = (u_int16_t *)&query[totallen];
- *type = htons(300);
+ pack16(p, htons(300));
totallen += 2;
+ p += 2;
/* hmac size */
- type = (u_int16_t *)&query[totallen];
- *type = htons(sizeof(shabuf));
+ pack16(p, htons(sizeof(shabuf)));
totallen += 2;
+ p += 2;
/* hmac */
memcpy(&query[totallen], shabuf, sizeof(shabuf));
totallen += sizeof(shabuf);
+ p += sizeof(shabuf);
/* original id */
- type = (u_int16_t *)&query[totallen];
- *type = wh->dh.id;
+ pack16(p, wh->dh.id);
totallen += 2;
+ p += 2;
/* error */
- type = (u_int16_t *)&query[totallen];
- *type = 0;
+ pack16(p, 0);
totallen += 2;
+ p += 2;
/* other len */
- type = (u_int16_t *)&query[totallen];
- *type = 0;
+ pack16(p, 0);
totallen += 2;
+ p += 2;
wh->dh.additional = htons(1);
}
@@ -2206,4 +2237,59 @@ dn_contains(char *name, int len, char *anchorname, int
}
return 0;
+}
+
+/* pack functions */
+
+void
+pack32(char *buf, u_int32_t value)
+{
+ pack(buf, (char *)&value, sizeof(uint32_t));
+}
+
+void
+pack16(char *buf, u_int16_t value)
+{
+ pack(buf, (char *)&value, sizeof(uint16_t));
+}
+
+void
+pack8(char *buf, u_int8_t value)
+{
+ u_int8_t *p;
+
+ p = (u_int8_t *)buf;
+ *p = value;
+}
+
+void
+pack(char *buf, char *input, int len)
+{
+ memcpy(buf, input, len);
+}
+
+uint32_t
+unpack32(char *buf)
+{
+ uint32_t ret = 0;
+
+ unpack((char *)&ret, buf, sizeof(uint32_t));
+
+ return (ret);
+}
+
+uint16_t
+unpack16(char *buf)
+{
+ uint16_t ret = 0;
+
+ unpack((char *)&ret, buf, sizeof(uint16_t));
+
+ return (ret);
+}
+
+void
+unpack(char *buf, char *input, int len)
+{
+ memcpy(buf, input, len);
}
repomaster@centroid.eu