]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: tree-wide: Avoid warnings about undefined entities retrieved from a CS
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Feb 2022 12:45:27 +0000 (13:45 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Feb 2022 12:56:52 +0000 (13:56 +0100)
Since recent changes related to the conn-stream/stream-interface
refactoring, GCC reports potential null pointer dereferences when we get the
appctx, the stream or the stream-interface from the conn-strem. Of course,
depending on the time, these entities may be null. But at many places, we
know they are defined and it is safe to get them without any check. Thus, we
use ALREADY_CHECKED() macro to silent these warnings.

Note that the refactoring is unfinished, so it is not a real issue for now.

include/haproxy/applet.h
include/haproxy/conn_stream.h
include/haproxy/stream_interface.h
src/hlua.c
src/http_ana.c
src/mux_pt.c
src/proxy.c
src/stats.c
src/stream.c

index 97b9c347b4fe55530a2c92d46ccf0f6b31a51484..b4c33ea26f89ee6fdff2116e2f32c185c3e6c6a1 100644 (file)
@@ -113,6 +113,8 @@ static inline void appctx_free(struct appctx *appctx)
 /* wakes up an applet when conditions have changed */
 static inline void appctx_wakeup(struct appctx *appctx)
 {
+       ALREADY_CHECKED(appctx);
+
        task_wakeup(appctx->t, TASK_WOKEN_OTHER);
 }
 
index 517d6d2f6f9617cebc3c61fb39720db7a5b264b7..5dc9cf265e1d2cf9b83b060d3aab1d680b38d5cd 100644 (file)
@@ -93,7 +93,7 @@ static inline struct check *cs_check(const struct conn_stream *cs)
 
 static inline struct stream_interface *cs_si(const struct conn_stream *cs)
 {
-       return (cs_strm(cs) ? cs->si : NULL);
+       return cs->si;
 }
 
 static inline const char *cs_get_data_name(const struct conn_stream *cs)
index 8119a423390c552fdb559c448f89d2fb38c0af1c..88fc16f831c7b2206be719c5dd677c3c796c884d 100644 (file)
@@ -55,13 +55,19 @@ void si_sync_send(struct stream_interface *si);
 /* returns the channel which receives data from this stream interface (input channel) */
 static inline struct channel *si_ic(struct stream_interface *si)
 {
-       return ((si->flags & SI_FL_ISBACK) ? &(cs_strm(si->cs)->res) : &(cs_strm(si->cs)->req));
+       struct stream *strm = cs_strm(si->cs);
+
+       ALREADY_CHECKED(strm);
+       return ((si->flags & SI_FL_ISBACK) ? &(strm->res) : &(strm->req));
 }
 
 /* returns the channel which feeds data to this stream interface (output channel) */
 static inline struct channel *si_oc(struct stream_interface *si)
 {
-       return ((si->flags & SI_FL_ISBACK) ? &(cs_strm(si->cs)->req) : &(cs_strm(si->cs)->res));
+       struct stream *strm = cs_strm(si->cs);
+
+       ALREADY_CHECKED(strm);
+       return ((si->flags & SI_FL_ISBACK) ? &(strm->req) : &(strm->res));
 }
 
 /* returns the buffer which receives data from this stream interface (input channel's buffer) */
@@ -79,19 +85,28 @@ static inline struct buffer *si_ob(struct stream_interface *si)
 /* returns the stream associated to a stream interface */
 static inline struct stream *si_strm(struct stream_interface *si)
 {
-       return cs_strm(si->cs);
+       struct stream *strm = cs_strm(si->cs);
+
+       ALREADY_CHECKED(strm);
+       return strm;
 }
 
 /* returns the task associated to this stream interface */
 static inline struct task *si_task(struct stream_interface *si)
 {
-       return cs_strm(si->cs)->task;
+       struct stream *strm = cs_strm(si->cs);
+
+       ALREADY_CHECKED(strm);
+       return strm->task;
 }
 
 /* returns the stream interface on the other side. Used during forwarding. */
 static inline struct stream_interface *si_opposite(struct stream_interface *si)
 {
-       return ((si->flags & SI_FL_ISBACK) ? cs_strm(si->cs)->csf->si : cs_strm(si->cs)->csb->si);
+       struct stream *strm = cs_strm(si->cs);
+
+       ALREADY_CHECKED(strm);
+       return ((si->flags & SI_FL_ISBACK) ? strm->csf->si : strm->csb->si);
 }
 
 /* initializes a stream interface in the SI_ST_INI state and create the event
index 3b2bd73efd445645868834a09f042b33e46f0aed..8b42746d8266fc44eae7b3b173d672e82c87e7cd 100644 (file)
@@ -2685,6 +2685,7 @@ __LJMP static int hlua_socket_connect_yield(struct lua_State *L, int status, lua
        }
 
        appctx = cs_appctx(s->csf);
+       ALREADY_CHECKED(appctx);
 
        /* Check for connection established. */
        if (appctx->ctx.hlua_cosocket.connected) {
@@ -4272,7 +4273,10 @@ static int hlua_applet_tcp_new(lua_State *L, struct appctx *ctx)
        struct hlua_appctx *luactx;
        struct stream_interface *si = cs_si(ctx->owner);
        struct stream *s = si_strm(si);
-       struct proxy *p = s->be;
+       struct proxy *p;
+
+       ALREADY_CHECKED(s);
+       p = s->be;
 
        /* Check stack size. */
        if (!lua_checkstack(L, 3))
index a3fd15cb74c65d20ceb0e25c9cf16c9669c597df..ff98a7bdd9780f404419e9b21023ba749493d180 100644 (file)
@@ -3883,6 +3883,7 @@ static int http_handle_stats(struct stream *s, struct channel *req)
        struct htx_sl *sl;
 
        appctx = cs_appctx(s->csb);
+       ALREADY_CHECKED(appctx);
        memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats));
        appctx->st1 = appctx->st2 = 0;
        appctx->ctx.stats.st_code = STAT_STATUS_INIT;
index 9f1aaa877efbf75aa1266b7ebb7ff1b0066b2ab5..1a706270f72d1a6a76eb797d21fdca01adbde5c2 100644 (file)
@@ -407,7 +407,10 @@ static void mux_pt_destroy_meth(void *ctx)
 static void mux_pt_detach(struct conn_stream *cs)
 {
        struct connection *conn = cs_conn(cs);
-       struct mux_pt_ctx *ctx = conn->ctx;
+       struct mux_pt_ctx *ctx;
+
+       ALREADY_CHECKED(conn);
+       ctx = conn->ctx;
 
        TRACE_ENTER(PT_EV_STRM_END, conn, cs);
 
index c392b4c6c92fdbd09ce47cdf0594d33eec68f7cf..c486376a5d463fa4531bf3b80a90e09ecb035f46 100644 (file)
@@ -2613,7 +2613,7 @@ static void dump_server_addr(const struct sockaddr_storage *addr, char *addr_str
 static int dump_servers_state(struct stream_interface *si)
 {
        struct appctx *appctx = cs_appctx(si->cs);
-       struct proxy *px = appctx->ctx.cli.p0;
+       struct proxy *px;
        struct server *srv;
        char srv_addr[INET6_ADDRSTRLEN + 1];
        char srv_agent_addr[INET6_ADDRSTRLEN + 1];
@@ -2622,6 +2622,9 @@ static int dump_servers_state(struct stream_interface *si)
        int bk_f_forced_id, srv_f_forced_id;
        char *srvrecord;
 
+       ALREADY_CHECKED(appctx);
+       px = appctx->ctx.cli.p0;
+
        if (!appctx->ctx.cli.p1)
                appctx->ctx.cli.p1 = px->srv;
 
index bffd3e395ee1e14c2c7466fd9f13e47e945213e2..854515b26333508b4756c7dd730db489b36fc423 100644 (file)
@@ -1984,6 +1984,8 @@ static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, st
        struct stats_module *mod;
        size_t stats_count = ST_F_TOTAL_FIELDS;
 
+       ALREADY_CHECKED(appctx);
+
        memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]);
 
        if (!stats_fill_li_stats(px, l, appctx->ctx.stats.flags, stats,
@@ -2495,6 +2497,8 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, st
        struct field *stats = stat_l[STATS_DOMAIN_PROXY];
        size_t stats_count = ST_F_TOTAL_FIELDS;
 
+       ALREADY_CHECKED(appctx);
+
        memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]);
 
        if (!stats_fill_sv_stats(px, sv, appctx->ctx.stats.flags, stats,
@@ -4205,6 +4209,8 @@ static int stats_send_http_redirect(struct stream_interface *si, struct htx *htx
        struct htx_sl *sl;
        unsigned int flags;
 
+       ALREADY_CHECKED(appctx);
+
        /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
        scope_txt[0] = 0;
        if (appctx->ctx.stats.scope_len) {
@@ -4518,6 +4524,8 @@ static int stats_dump_info_to_buffer(struct stream_interface *si)
 {
        struct appctx *appctx = cs_appctx(si->cs);
 
+       ALREADY_CHECKED(appctx);
+
        if (!stats_fill_info(info, INF_TOTAL_FIELDS, appctx->ctx.stats.flags))
                return 0;
 
index 935fce42ddb75901e1fc933e114585e9ca226c05..37cd79378ffb1d8daa6a69929d246fe41627367f 100644 (file)
@@ -980,11 +980,11 @@ enum act_return process_use_service(struct act_rule *rule, struct proxy *px,
        if (flags & ACT_OPT_FIRST) {
                /* Register applet. this function schedules the applet. */
                s->target = &rule->applet.obj_type;
-               if (unlikely(!si_register_handler(cs_si(s->csb), objt_applet(s->target))))
+               appctx = si_register_handler(cs_si(s->csb), objt_applet(s->target));
+               if (unlikely(!appctx))
                        return ACT_RET_ERR;
 
                /* Initialise the context. */
-               appctx = cs_appctx(s->csb);
                memset(&appctx->ctx, 0, sizeof(appctx->ctx));
                appctx->rule = rule;
        }
@@ -3101,6 +3101,8 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
        struct connection *conn;
        struct appctx *tmpctx;
 
+       ALREADY_CHECKED(appctx);
+
        chunk_reset(&trash);
 
        if (appctx->ctx.sess.section > 0 && appctx->ctx.sess.uid != strm->uniq_id) {