From: Ammar Faizi <[email protected]>
To: GNU/Weeb Mailing List <[email protected]>
Cc: Ammar Faizi <[email protected]>, Arthur Lapz <[email protected]>
Subject: [PATCH teavpn2] server: entry: Fix a false-positive warning from GCC 12.1.1
Date: Thu, 1 Sep 2022 20:49:54 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
@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 <[email protected]>
Tested-by: Arthur Lapz <[email protected]>
Signed-off-by: Ammar Faizi <[email protected]>
---
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
reply other threads:[~2022-09-01 13:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox