Fix possible buffer overflows in DNS handling