mirror of https://github.com/omar-polo/gmid.git
don't crash on wrong vhost or missing SNI
the new logging code was crashing if the client didn't support SNI or if required an unknown vhost: this because we short-circuit in handle_handshake to an error, so c->iri isn't populated yet (we don't even read the request). fixes #1
This commit is contained in:
parent
0be51733ef
commit
0ab65593e2
22
gmid.c
22
gmid.c
|
@ -119,15 +119,19 @@ log_request(struct client *c, char *meta, size_t l)
|
||||||
if (ec != 0)
|
if (ec != 0)
|
||||||
fatal("getnameinfo: %s", gai_strerror(ec));
|
fatal("getnameinfo: %s", gai_strerror(ec));
|
||||||
|
|
||||||
/* serialize the IRI */
|
if (c->iri.schema != NULL) {
|
||||||
strlcpy(b, c->iri.schema, sizeof(b));
|
/* serialize the IRI */
|
||||||
strlcat(b, "://", sizeof(b));
|
strlcpy(b, c->iri.schema, sizeof(b));
|
||||||
strlcat(b, c->iri.host, sizeof(b));
|
strlcat(b, "://", sizeof(b));
|
||||||
strlcat(b, "/", sizeof(b));
|
strlcat(b, c->iri.host, sizeof(b));
|
||||||
strlcat(b, c->iri.path, sizeof(b)); /* TODO: sanitize UTF8 */
|
strlcat(b, "/", sizeof(b));
|
||||||
if (*c->iri.query != '\0') { /* TODO: sanitize UTF8 */
|
strlcat(b, c->iri.path, sizeof(b)); /* TODO: sanitize UTF8 */
|
||||||
strlcat(b, "?", sizeof(b));
|
if (*c->iri.query != '\0') { /* TODO: sanitize UTF8 */
|
||||||
strlcat(b, c->iri.query, sizeof(b));
|
strlcat(b, "?", sizeof(b));
|
||||||
|
strlcat(b, c->iri.query, sizeof(b));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
strlcpy(b, c->req, sizeof(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((t = gmid_strnchr(meta, '\r', l)) == NULL)
|
if ((t = gmid_strnchr(meta, '\r', l)) == NULL)
|
||||||
|
|
5
server.c
5
server.c
|
@ -196,6 +196,11 @@ handle_handshake(struct pollfd *fds, struct client *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostnotfound:
|
hostnotfound:
|
||||||
|
if (servname != NULL)
|
||||||
|
strncpy(c->req, servname, sizeof(c->req));
|
||||||
|
else
|
||||||
|
strncpy(c->req, "null", sizeof(c->req));
|
||||||
|
|
||||||
/* XXX: check the correct response */
|
/* XXX: check the correct response */
|
||||||
if (!start_reply(fds, c, BAD_REQUEST, "Wrong host or missing SNI"))
|
if (!start_reply(fds, c, BAD_REQUEST, "Wrong host or missing SNI"))
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue