diff options
Diffstat (limited to 'usr.sbin/nsd/rdata.c')
-rw-r--r-- | usr.sbin/nsd/rdata.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/usr.sbin/nsd/rdata.c b/usr.sbin/nsd/rdata.c index 26f4b703b8c..796eda55a94 100644 --- a/usr.sbin/nsd/rdata.c +++ b/usr.sbin/nsd/rdata.c @@ -87,11 +87,17 @@ rdata_dns_name_to_string(buffer_type *output, rdata_atom_type rdata, buffer_printf(output, "."); for (i = 1; i <= length; ++i) { - char ch = (char) data[i+offset]; - if (isprint((int)ch)) - buffer_printf(output, "%c", ch); - else - buffer_printf(output, "\\%03u", (unsigned) ch); + uint8_t ch = data[i+offset]; + + if (ch=='.' || ch==';' || ch=='(' || ch==')' || ch=='\\') { + buffer_printf(output, "\\%c", (char) ch); + } else if (!isgraph((int) ch)) { + buffer_printf(output, "\\%03u", (unsigned int) ch); + } else if (isprint((int) ch)) { + buffer_printf(output, "%c", (char) ch); + } else { + buffer_printf(output, "\\%03u", (unsigned int) ch); + } } /* next label */ offset = offset+length+1; @@ -128,6 +134,34 @@ rdata_text_to_string(buffer_type *output, rdata_atom_type rdata, } static int +rdata_texts_to_string(buffer_type *output, rdata_atom_type rdata, + rr_type* ATTR_UNUSED(rr)) +{ + uint16_t pos = 0; + const uint8_t *data = rdata_atom_data(rdata); + uint16_t length = rdata_atom_size(rdata); + size_t i; + + while (pos < length && pos + data[pos] < length) { + buffer_printf(output, "\""); + for (i = 1; i <= data[pos]; ++i) { + char ch = (char) data[pos + i]; + if (isprint((int)ch)) { + if (ch == '"' || ch == '\\') { + buffer_printf(output, "\\"); + } + buffer_printf(output, "%c", ch); + } else { + buffer_printf(output, "\\%03u", (unsigned) ch); + } + } + pos += data[pos]+1; + buffer_printf(output, pos < length?"\" ":"\""); + } + return 1; +} + +static int rdata_byte_to_string(buffer_type *output, rdata_atom_type rdata, rr_type* ATTR_UNUSED(rr)) { @@ -509,6 +543,7 @@ static rdata_to_string_type rdata_to_string_table[RDATA_ZF_UNKNOWN + 1] = { rdata_dname_to_string, rdata_dns_name_to_string, rdata_text_to_string, + rdata_texts_to_string, rdata_byte_to_string, rdata_short_to_string, rdata_long_to_string, @@ -549,7 +584,7 @@ rdata_wireformat_to_rdata_atoms(region_type *region, rdata_atom_type **rdatas) { size_t end = buffer_position(packet) + data_size; - ssize_t i; + size_t i; rdata_atom_type temp_rdatas[MAXRDATALEN]; rrtype_descriptor_type *descriptor = rrtype_descriptor_by_type(rrtype); region_type *temp_region; @@ -588,6 +623,9 @@ rdata_wireformat_to_rdata_atoms(region_type *region, case RDATA_WF_LONG: length = sizeof(uint32_t); break; + case RDATA_WF_TEXTS: + length = data_size; + break; case RDATA_WF_TEXT: case RDATA_WF_BINARYWITHLENGTH: /* Length is stored in the first byte. */ @@ -687,7 +725,7 @@ rdata_wireformat_to_rdata_atoms(region_type *region, *rdatas = (rdata_atom_type *) region_alloc_init( region, temp_rdatas, i * sizeof(rdata_atom_type)); region_destroy(temp_region); - return i; + return (ssize_t)i; } size_t |