]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: make the debugging helper functions safer
authorWilly Tarreau <w@1wt.eu>
Thu, 25 Apr 2019 16:35:49 +0000 (18:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Apr 2019 16:35:49 +0000 (18:35 +0200)
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.

include/proto/connection.h

index 0db7c47d00782b542db1270b08c64a40fe3876a8..f1919ce717c0f2e50af729bc006c12a6886a1960 100644 (file)
@@ -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;
 }