From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [182.2.38.99]) by gnuweeb.org (Postfix) with ESMTPSA id 7763E80927; Thu, 1 Sep 2022 13:50:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662040207; bh=DuSPo2SDzgiByoX7UocxBJSRdUzVchfxlpsdqecuOfo=; h=From:To:Cc:Subject:Date:From; b=bipDJYOBw9iIE1GtCwBVx2komjhQ17vHZA1nAcc4IOWOlwMEaPpdA+UOtuvvR3GrH Y9VDpRA3Y8qnkjVGDpZVWg/+upk1ULJD4ZNQKMmoM7IIjb5ue3lV7UhnYUsr966f0N oFqwZGt2yt8xUuc0A6C7ORecwe9sn6O+F+r7gERPld7odC8sFwqV8uaYUiUQi7451d z43HuMuPlxax6IqbRVslYSb6r433S/b3i2bIxYZYqhoLskwjaXYHzRl+u7dj91n28x 0TlofU+9qgtFDYd2wrMfBGzdOPrHP3b5XhNRk6W4s3hN9Fj4S0lhWVxnFz/ki0sxzH 1+Kqw5drTvIXQ== From: Ammar Faizi To: GNU/Weeb Mailing List Cc: Ammar Faizi , Arthur Lapz Subject: [PATCH teavpn2] server: entry: Fix a false-positive warning from GCC 12.1.1 Date: Thu, 1 Sep 2022 20:49:54 +0700 Message-Id: <20220901134954.1462309-1-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: @rlapz reported that he is seeing a dangling pointer warning when building TeaVPN2 with GCC 12.1.1 [1]: src/teavpn2/server/entry.c: In function ‘run_server’: src/teavpn2/server/entry.c:455:18: warning: storing the address of \ local variable ‘cfg’ in ‘data_dir’ [-Wdangling-pointer=] 455 | data_dir = cfg.sys.data_dir; | ~~~~~~~~~^~~~~~~~~~~~~~~~~~ This is a false-positive warning. GCC doesn't really know the real program flow at runtime. Reasoning why GCC is wrong: 1) The lifetime of cfg.sys.data dir ends when run_server() in entry.c returns. 2) @data_dir is only used in teavpn2_auth() in auth.c. 3) teavpn2_auth() is only called in the run_server() call stack. That being said, when @data_dir var is used, it never be a dangling pointer. Just to make GCC happy on this, set @data_dir to NULL before the function returns, this way GCC assumption about dangling pointer should be proven wrong at compile time. @rlapz confirmed it fixes the warning. Link: https://t.me/GNUWeeb/662168 [1] Reported-by: Arthur Lapz Tested-by: Arthur Lapz Signed-off-by: Ammar Faizi --- src/teavpn2/server/entry.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/teavpn2/server/entry.c b/src/teavpn2/server/entry.c index fd9bc85..6f47ef9 100644 --- a/src/teavpn2/server/entry.c +++ b/src/teavpn2/server/entry.c @@ -455,9 +455,13 @@ __cold int run_server(int argc, char *argv[]) data_dir = cfg.sys.data_dir; switch (cfg.sock.type) { case SOCK_UDP: - return -teavpn2_server_udp_run(&cfg); + ret = -teavpn2_server_udp_run(&cfg); + break; case SOCK_TCP: default: - return ESOCKTNOSUPPORT; + ret = ESOCKTNOSUPPORT; + break; } + data_dir = NULL; + return ret; } base-commit: cfee418df11d3b1c67ed96da25807462f68b3c9c -- Ammar Faizi