From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3D4003858C78; Mon, 9 Jan 2023 19:55:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D4003858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673294151; bh=BZLtlkkazE6qvTp9sKax12G+UPU0cjnwnYEAHmOFIpA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ycDy8mL+SPIs7+KaDpYOTp6t9OBUByLANObC1Zap8guCykLM7byYEGkn0oSncf18v sLN7BNViwiWNlxPZGDlgo59rEQSYoIFl56Jn92qd64ktRiLYz+gydijS4Md2X2/2S5 w6MD588myqQhfKeWLS6CAqKUVm0XQkceM4V7dMio= From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/108251] false positive: null dereference Date: Mon, 09 Jan 2023 19:55:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108251 --- Comment #6 from David Malcolm --- The analyzer sees the error-handling case in objt_conn, and considers the execution path where it bails out early due to "t" being NULL i.e. smp->sess->origin is NULL, and thus conn being initialized to NULL. At it turns out, ssl_sock_get_ssl_object is defined (in src/ssl_sock.c) as: SSL *ssl_sock_get_ssl_object(struct connection *conn) { struct ssl_sock_ctx *ctx =3D conn_get_ssl_sock_ctx(conn); return ctx ? ctx->ssl : NULL; } and conn_get_ssl_sock_ctx is defined (in include/haproxy/connection.h) as: /* retrieves the ssl_sock_ctx for this connection otherwise NULL */ static inline struct ssl_sock_ctx *conn_get_ssl_sock_ctx(struct connection *conn) { if (!conn || !conn->xprt || !conn->xprt->get_ssl_sock_ctx) return NULL; return conn->xprt->get_ssl_sock_ctx(conn); } Hence it's a false positive: if conn is NULL, then ssl_sock_get_ssl_object = will return NULL. The TU "sees" the definition of conn_get_ssl_sock_ctx, but only the declara= tion of ssl_sock_get_ssl_object, not the latter's declaration. Without a definition of ssl_sock_get_ssl_object, -fanalyzer can't "know" of= the interaction between "ssl" and "conn" (-fanalyzer doesn't work well with LTO yet). Hence it erroneously considers the case that ssl_sock_get_ssl_object could return non-NULL on a NULL "conn", and sees the deref of conn, which it repo= rts.=