mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
conn: Properly close MetricsPort socket on EOF
Handle the EOF situation for a metrics connection. Furthermore, if we failed to fetch the data from the inbuf properly, mark the socket as closed because the caller, connection_process_inbuf(), assumes that we did so on error. Fixes #40257 Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
committed by
Nick Mathewson
parent
f420eacf18
commit
01c4abc2d4
@@ -20,6 +20,7 @@
|
||||
#include "lib/net/address.h"
|
||||
|
||||
#include "core/mainloop/connection.h"
|
||||
#include "core/or/connection_or.h"
|
||||
#include "core/or/connection_st.h"
|
||||
#include "core/or/policies.h"
|
||||
#include "core/or/port_cfg_st.h"
|
||||
@@ -93,7 +94,8 @@ metrics_get_output(const metrics_format_t fmt)
|
||||
|
||||
/** Process what is in the inbuf of this connection of type metrics.
|
||||
*
|
||||
* Return 0 on success else -1 on error which will close the connection. */
|
||||
* Return 0 on success else -1 on error for which the connection is marked for
|
||||
* close. */
|
||||
int
|
||||
metrics_connection_process_inbuf(connection_t *conn)
|
||||
{
|
||||
@@ -111,13 +113,14 @@ metrics_connection_process_inbuf(connection_t *conn)
|
||||
goto err;
|
||||
}
|
||||
|
||||
const int http_status = fetch_from_buf_http(conn->inbuf, &headers, 1024,
|
||||
NULL, NULL, 1024, 0);
|
||||
const int http_status =
|
||||
connection_fetch_from_buf_http(conn, &headers, 1024, NULL, NULL, 1024, 0);
|
||||
if (http_status < 0) {
|
||||
errmsg = "HTTP/1.0 400 Bad Request\r\n\r\n";
|
||||
goto err;
|
||||
} else if (http_status == 0) {
|
||||
/* no HTTP request yet. */
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -155,6 +158,7 @@ metrics_connection_process_inbuf(connection_t *conn)
|
||||
log_info(LD_EDGE, "HTTP metrics error: saying %s", escaped(errmsg));
|
||||
connection_buf_add(errmsg, strlen(errmsg), conn);
|
||||
}
|
||||
connection_mark_and_flush(conn);
|
||||
|
||||
done:
|
||||
tor_free(headers);
|
||||
@@ -243,6 +247,17 @@ metrics_parse_ports(or_options_t *options, smartlist_t *ports,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Called when conn has gotten its socket closed. */
|
||||
int
|
||||
metrics_connection_reached_eof(connection_t *conn)
|
||||
{
|
||||
tor_assert(conn);
|
||||
|
||||
log_info(LD_EDGE, "Metrics connection reached EOF. Closing.");
|
||||
connection_mark_for_close(conn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Initialize the subsystem. */
|
||||
void
|
||||
metrics_init(void)
|
||||
|
||||
@@ -27,6 +27,7 @@ buf_t *metrics_get_output(const metrics_format_t fmt);
|
||||
|
||||
/* Connection. */
|
||||
int metrics_connection_process_inbuf(struct connection_t *conn);
|
||||
int metrics_connection_reached_eof(struct connection_t *conn);
|
||||
|
||||
/* Configuration. */
|
||||
int metrics_parse_ports(or_options_t *options, smartlist_t *ports,
|
||||
|
||||
Reference in New Issue
Block a user