aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/librdns
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-02 18:16:50 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-02 18:17:27 +0100
commitc4c098a34a1c93c02959fa09ea56798f27ab6d20 (patch)
tree941fc57f699456ac543256b72b20a15d5a738663 /contrib/librdns
parentfcf273b01fa0b7307ae004ce9767c82c477d0e21 (diff)
downloadrspamd-c4c098a34a1c93c02959fa09ea56798f27ab6d20.tar.gz
rspamd-c4c098a34a1c93c02959fa09ea56798f27ab6d20.zip
[Minor] Fix DNS packet writing to avoid alignment issues
Diffstat (limited to 'contrib/librdns')
-rw-r--r--contrib/librdns/packet.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/contrib/librdns/packet.c b/contrib/librdns/packet.c
index e3020d7e8..35f4a9601 100644
--- a/contrib/librdns/packet.c
+++ b/contrib/librdns/packet.c
@@ -235,18 +235,23 @@ rdns_format_dns_name (struct rdns_resolver *resolver, const char *in,
return false;
}
+#define U16_TO_WIRE_ADVANCE(val, p8) \
+ *p8++ = (uint8_t)(((uint16_t)(val)) >> 8); \
+ *p8++ = (uint8_t)(((uint16_t)(val)) & 0xFF);
+
bool
rdns_add_rr (struct rdns_request *req, const char *name, unsigned int len,
enum dns_type type, struct rdns_compression_entry **comp)
{
- uint16_t *p;
+ uint8_t *p8;
if (!rdns_write_name_compressed (req, name, len, comp)) {
return false;
}
- p = (uint16_t *)(req->packet + req->pos);
- *p++ = htons (type);
- *p = htons (DNS_C_IN);
+
+ p8 = (req->packet + req->pos);
+ U16_TO_WIRE_ADVANCE (type, p8);
+ U16_TO_WIRE_ADVANCE (DNS_C_IN, p8);
req->pos += sizeof (uint16_t) * 2;
return true;
@@ -256,18 +261,13 @@ bool
rdns_add_edns0 (struct rdns_request *req)
{
uint8_t *p8;
- uint16_t *p16;
-
- p8 = (uint8_t *)(req->packet + req->pos);
- *p8 = '\0'; /* Name is root */
- p16 = (uint16_t *)(req->packet + req->pos + 1);
- *p16++ = htons (DNS_T_OPT);
- /* UDP packet length */
- *p16++ = htons (UDP_PACKET_SIZE);
- /* Extended rcode 00 00 */
- *p16++ = 0;
- /* Z 10000000 00000000 to allow dnssec */
- p8 = (uint8_t *)p16;
+
+ p8 = (req->packet + req->pos);
+ *p8++ = '\0'; /* Name is root */
+ U16_TO_WIRE_ADVANCE (DNS_T_OPT, p8);
+ U16_TO_WIRE_ADVANCE (UDP_PACKET_SIZE, p8);
+ U16_TO_WIRE_ADVANCE (0, p8);
+
if (req->resolver->enable_dnssec) {
*p8++ = 0x80;
}
@@ -275,9 +275,9 @@ rdns_add_edns0 (struct rdns_request *req)
*p8++ = 0x00;
}
*p8++ = 0;
- p16 = (uint16_t *)p8;
/* Length */
- *p16 = 0;
+ U16_TO_WIRE_ADVANCE (0, p8);
+
req->pos += sizeof (uint8_t) + sizeof (uint16_t) * 5;
return true;