From: Willy Tarreau Date: Thu, 25 Apr 2019 16:35:49 +0000 (+0200) Subject: MINOR: connection: make the debugging helper functions safer X-Git-Tag: v2.0-dev3~166 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e6a5b3a6e65bb49ee3220070f1754e9b743c600;p=thirdparty%2Fhaproxy.git MINOR: connection: make the debugging helper functions safer We have various functions like conn_get_ctrl_name() to retrieve some information reported in "show sess" for debugging, which assume that the connection is valid. This is really not convenient in code aimed at debugging and is error-prone. Let's add a validity test first. --- diff --git a/include/proto/connection.h b/include/proto/connection.h index 0db7c47d00..f1919ce717 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -894,28 +894,28 @@ static inline const char *conn_err_code_str(struct connection *c) static inline const char *conn_get_ctrl_name(const struct connection *conn) { - if (!conn_ctrl_ready(conn)) + if (!conn || !conn_ctrl_ready(conn)) return "NONE"; return conn->ctrl->name; } static inline const char *conn_get_xprt_name(const struct connection *conn) { - if (!conn_xprt_ready(conn)) + if (!conn || !conn_xprt_ready(conn)) return "NONE"; return conn->xprt->name; } static inline const char *conn_get_mux_name(const struct connection *conn) { - if (!conn->mux) + if (!conn || !conn->mux) return "NONE"; return conn->mux->name; } static inline const char *cs_get_data_name(const struct conn_stream *cs) { - if (!cs->data_cb) + if (!cs || !cs->data_cb) return "NONE"; return cs->data_cb->name; }