git ssb

0+

cel / sslh



Commit 00d5872aa176a23588f143551aa4b7e8dd1c0ca6

ignore brackets in hostname in config files

Yves Rutschle committed on 4/21/2017, 8:33:02 PM
Parent: 7d561af4235ffc6c0203fc66d4998c74384c7fa8

Files changed

common.cchanged
common.hchanged
common.cView
@@ -441,18 +441,33 @@
441441 }
442442
443443 /* Turns a hostname and port (or service) into a list of struct addrinfo
444444 * returns 0 on success, -1 otherwise and logs error
445+ *
446+ * *host gets modified
445447 **/
446-int resolve_split_name(struct addrinfo **out, const char* host, const char* serv)
448+int resolve_split_name(struct addrinfo **out, char* host, const char* serv)
447449 {
448450 struct addrinfo hint;
451+ char *end;
449452 int res;
450453
451454 memset(&hint, 0, sizeof(hint));
452455 hint.ai_family = PF_UNSPEC;
453456 hint.ai_socktype = SOCK_STREAM;
454457
458+ /* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets
459+ * around IP address */
460+ if (host[0] == '[') {
461+ end = strrchr(host, ']');
462+ if (!end) {
463+ fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host);
464+ }
465+ host++; /* skip first bracket */
466+ *end = 0; /* remove last bracket */
467+ }
468+
469+
455470 res = getaddrinfo(host, serv, &hint, out);
456471 if (res)
457472 log_message(LOG_ERR, "%s `%s:%s'\n", gai_strerror(res), host, serv);
458473 return res;
@@ -463,9 +478,9 @@
463478 fullname: input string -- it gets clobbered
464479 */
465480 void resolve_name(struct addrinfo **out, char* fullname)
466481 {
467- char *serv, *host, *end;
482+ char *serv, *host;
468483 int res;
469484
470485 /* Find port */
471486 char *sep = strrchr(fullname, ':');
@@ -477,19 +492,8 @@
477492 *sep = 0;
478493
479494 host = fullname;
480495
481- /* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets
482- * around IP address */
483- if (host[0] == '[') {
484- end = strrchr(host, ']');
485- if (!end) {
486- fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host);
487- }
488- host++; /* skip first bracket */
489- *end = 0; /* remove last bracket */
490- }
491-
492496 res = resolve_split_name(out, host, serv);
493497 if (res) {
494498 fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname);
495499 if (res == EAI_SERVICE)
common.hView
@@ -105,9 +105,9 @@
105105 void drop_privileges(const char* user_name);
106106 void write_pid_file(const char* pidfile);
107107 void log_message(int type, char* msg, ...);
108108 void dump_connection(struct connection *cnx);
109-int resolve_split_name(struct addrinfo **out, const char* hostname, const char* port);
109+int resolve_split_name(struct addrinfo **out, char* hostname, const char* port);
110110
111111 int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);
112112
113113 int defer_write(struct queue *q, void* data, int data_size);

Built with git-ssb-web