]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: ssl: silence build warning on uninitialised counters
authorWilly Tarreau <w@1wt.eu>
Fri, 6 Nov 2020 12:19:18 +0000 (13:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 Nov 2020 12:22:44 +0000 (13:22 +0100)
Since commit d0447a7c3 ("MINOR: ssl: add counters for ssl sessions"),
gcc 9+ complains about this:

  CC      src/ssl_sock.o
src/ssl_sock.c: In function 'ssl_sock_io_cb':
src/ssl_sock.c:5416:3: warning: 'counters_px' may be used uninitialized in this function [-Wmaybe-uninitialized]
 5416 |   ++counters_px->reused_sess;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~
src/ssl_sock.c:5133:23: note: 'counters_px' was declared here
 5133 |  struct ssl_counters *counters, *counters_px;
      |                                  ^~~~~~~~~~~

Either a listener or a server are expected there, so ther counters are
always initialized and the compiler cannot know this. Let's preset
them and test before updating the counter, we're not in a hot path
here.

No backport is needed.

src/ssl_sock.c

index c8ea19f14133ee315097bdd5f4805335358b56fb..9072752f2d361a1687a159095316741a91331192 100644 (file)
@@ -5129,7 +5129,8 @@ static int ssl_sock_handshake(struct connection *conn, unsigned int flag)
 {
        struct ssl_sock_ctx *ctx = conn->xprt_ctx;
        int ret;
-       struct ssl_counters *counters, *counters_px;
+       struct ssl_counters *counters = NULL;
+       struct ssl_counters *counters_px = NULL;
        struct listener *li;
        struct server *srv;
 
@@ -5405,10 +5406,12 @@ reneg_ok:
                                global.ssl_fe_keys_max = global.ssl_fe_keys_per_sec.curr_ctr;
                }
 
-               ++counters->sess;
-               ++counters_px->sess;
+               if (counters) {
+                       ++counters->sess;
+                       ++counters_px->sess;
+               }
        }
-       else {
+       else if (counters) {
                ++counters->reused_sess;
                ++counters_px->reused_sess;
        }