BUILD: tree-wide: Avoid warnings about undefined entities retrieved from a CS

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.
This commit is contained in:
Christopher Faulet 2022-02-24 13:45:27 +01:00
parent 9264a2c0e8
commit 2da02ae8b2
9 changed files with 49 additions and 11 deletions

View 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);
}

View 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)

View 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

View 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))

View 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;

View 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);

View 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;

View 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;

View 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) {