Commit b487384f authored by Daniel Salzman's avatar Daniel Salzman

conf: fix UNIX socket relative path processing

parent bdb05fa2
......@@ -1135,14 +1135,17 @@ struct sockaddr_storage conf_addr(
conf_db_val(val);
out = yp_addr(val->data, val->len, &port);
// val->data[0] is socket type identifier.
if (out.ss_family == AF_UNIX && val->data[1] != '/' &&
sock_base_dir != NULL) {
char *tmp = sprintf_alloc("%s/%.*s", sock_base_dir,
(int)val->len - 1,
val->data + 1);
val->code = sockaddr_set(&out, AF_UNIX, tmp, 0);
free(tmp);
if (out.ss_family == AF_UNIX) {
// val->data[0] is socket type identifier!
if (val->data[1] == '/' || sock_base_dir == NULL) {
val->code = sockaddr_set(&out, AF_UNIX,
(char *)val->data + 1, 0);
} else {
char *tmp = sprintf_alloc("%s/%s", sock_base_dir,
val->data + 1);
val->code = sockaddr_set(&out, AF_UNIX, tmp, 0);
free(tmp);
}
} else if (port != -1) {
sockaddr_port_set(&out, port);
} else {
......@@ -1151,14 +1154,14 @@ struct sockaddr_storage conf_addr(
} else {
const char *dflt_socket = val->item->var.a.dflt_socket;
if (dflt_socket != NULL) {
if (dflt_socket[0] != '/' && sock_base_dir != NULL) {
if (dflt_socket[0] == '/' || sock_base_dir == NULL) {
val->code = sockaddr_set(&out, AF_UNIX,
dflt_socket, 0);
} else {
char *tmp = sprintf_alloc("%s/%s", sock_base_dir,
dflt_socket);
val->code = sockaddr_set(&out, AF_UNIX, tmp, 0);
free(tmp);
} else {
val->code = sockaddr_set(&out, AF_UNIX,
dflt_socket, 0);
}
}
}
......
......@@ -314,7 +314,7 @@ static int addr_to_bin(
addr = &(addr6.s6_addr);
} else if (allow_unix && txt_len > 0) {
type = 0;
addr_len = txt_len;
addr_len = txt_len + 1; // + trailing zero.
addr = txt;
} else {
return KNOT_EINVAL;
......@@ -344,7 +344,7 @@ static int addr_to_txt(
int ret;
switch (type) {
case 0:
ret = snprintf(txt, *txt_len, "%.*s", (int)bin_len, bin);
ret = snprintf(txt, *txt_len, "%s", bin);
if (ret <= 0 || ret >= *txt_len) {
return KNOT_ESPACE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment