mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 09:21:26 +03:00
dns-domain: make sure dns_name_to_wire_format() may properly encode the root domain
The root domain consists of zero labels, and we should be able to encode that.
This commit is contained in:
parent
1dfbf0007a
commit
c6cefd13eb
@ -866,19 +866,17 @@ bool dns_name_is_single_label(const char *name) {
|
|||||||
|
|
||||||
/* Encode a domain name according to RFC 1035 Section 3.1 */
|
/* Encode a domain name according to RFC 1035 Section 3.1 */
|
||||||
int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len) {
|
int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len) {
|
||||||
uint8_t *label_length;
|
uint8_t *label_length, *out;
|
||||||
uint8_t *out;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert_return(buffer, -EINVAL);
|
assert(domain);
|
||||||
assert_return(domain, -EINVAL);
|
assert(buffer);
|
||||||
assert_return(domain[0], -EINVAL);
|
|
||||||
|
|
||||||
out = buffer;
|
out = buffer;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* reserve a byte for label length */
|
/* reserve a byte for label length */
|
||||||
if (len == 0)
|
if (len <= 0)
|
||||||
return -ENOBUFS;
|
return -ENOBUFS;
|
||||||
len--;
|
len--;
|
||||||
label_length = out;
|
label_length = out;
|
||||||
|
@ -66,11 +66,12 @@ static void test_dns_name_to_wire_format_one(const char *what, const char *expec
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_dns_name_to_wire_format(void) {
|
static void test_dns_name_to_wire_format(void) {
|
||||||
|
const char out0[] = { 0 };
|
||||||
const char out1[] = { 3, 'f', 'o', 'o', 0 };
|
const char out1[] = { 3, 'f', 'o', 'o', 0 };
|
||||||
const char out2[] = { 5, 'h', 'a', 'l', 'l', 'o', 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', 0 };
|
const char out2[] = { 5, 'h', 'a', 'l', 'l', 'o', 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', 0 };
|
||||||
const char out3[] = { 4, ' ', 'f', 'o', 'o', 3, 'b', 'a', 'r', 0 };
|
const char out3[] = { 4, ' ', 'f', 'o', 'o', 3, 'b', 'a', 'r', 0 };
|
||||||
|
|
||||||
test_dns_name_to_wire_format_one("", NULL, 0, -EINVAL);
|
test_dns_name_to_wire_format_one("", out0, sizeof(out0), sizeof(out0));
|
||||||
|
|
||||||
test_dns_name_to_wire_format_one("foo", out1, sizeof(out1), sizeof(out1));
|
test_dns_name_to_wire_format_one("foo", out1, sizeof(out1), sizeof(out1));
|
||||||
test_dns_name_to_wire_format_one("foo", out1, sizeof(out1) + 1, sizeof(out1));
|
test_dns_name_to_wire_format_one("foo", out1, sizeof(out1) + 1, sizeof(out1));
|
||||||
|
Loading…
Reference in New Issue
Block a user