Don't clobber data in libconfig space, copy it before

changing it. So far it worked, but really that's not
respecting the contract.
This commit is contained in:
Yves Rutschlé 2018-01-07 16:43:50 +00:00
parent bc72c4ac42
commit 7bf3e12c30
2 changed files with 12 additions and 6 deletions

View File

@ -450,19 +450,25 @@ char* sprintaddr(char* buf, size_t size, struct addrinfo *a)
/* Turns a hostname and port (or service) into a list of struct addrinfo
* returns 0 on success, -1 otherwise and logs error
*
* *host gets modified
**/
int resolve_split_name(struct addrinfo **out, char* host, const char* serv)
*/
int resolve_split_name(struct addrinfo **out, const char* ct_host, const char* serv)
{
struct addrinfo hint;
char *end;
int res;
char* host;
memset(&hint, 0, sizeof(hint));
hint.ai_family = PF_UNSPEC;
hint.ai_socktype = SOCK_STREAM;
/* Copy parameter so not to clobber data in libconfig */
res = asprintf(&host, "%s", ct_host);
if (res == -1) {
log_message(LOG_ERR, "asprintf: cannot allocate memory");
return -1;
}
/* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets
* around IP address */
if (host[0] == '[') {
@ -474,10 +480,10 @@ int resolve_split_name(struct addrinfo **out, char* host, const char* serv)
*end = 0; /* remove last bracket */
}
res = getaddrinfo(host, serv, &hint, out);
if (res)
log_message(LOG_ERR, "%s `%s:%s'\n", gai_strerror(res), host, serv);
free(host);
return res;
}

View File

@ -106,7 +106,7 @@ void drop_privileges(const char* user_name, const char* chroot_path);
void write_pid_file(const char* pidfile);
void log_message(int type, char* msg, ...);
void dump_connection(struct connection *cnx);
int resolve_split_name(struct addrinfo **out, char* hostname, const char* port);
int resolve_split_name(struct addrinfo **out, const char* hostname, const char* port);
int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);