mnezerka / dnslib

Simple C++ library designed for encoding and decoding of DNS protocol packets
62 stars 23 forks source link

malformed when domain name end with '.' #4

Closed jiangzhuti closed 5 years ago

jiangzhuti commented 5 years ago

e.g. Buffer::putDnsDomainName("abc.com.")

dig could properly handle this

mnezerka commented 5 years ago

Not sure if I fully understand your proint. Could you provide more details (e.g. fragment of code and error output), please?

jiangzhuti commented 5 years ago

Not sure if I fully understand your proint. Could you provide more details (e.g. fragment of code and error output), please?

if domain name end with '.'(for example, "abc.com."), then https://github.com/mnezerka/dnslib/blob/master/src/buffer.cpp#L410 will take true branch ,the result dns packet is like this: "0x03 0x61 0x62 0x63 0x03 0x63 0x6f 0x6d 0xc0 0x00", 0xc0 is unwanted.

mnezerka commented 5 years ago

I tried it and from my experiments, it seems that Buffer::putDnsDomainName("abc.com.") generates this: 0x03 0x61 0x62 0x63 0x03 0x63 0x6f 0x6d 0x00 0x00, so the dot at the ends generates one additional empty label. As I understand, it is unwanted. I'll prepare fix which will ignore dot at the end.

mnezerka commented 5 years ago

I addressed this issue in a55c42aaf4926684029fac47f37293fc5f342d0b. I hope it is solved.