pex: fix null pointer check
authorFelix Fietkau <nbd@nbd.name>
Tue, 23 Aug 2022 20:35:54 +0000 (22:35 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 23 Aug 2022 20:38:46 +0000 (22:38 +0200)
check for local_host null pointer before dereferencing it

Signed-off-by: Felix Fietkau <nbd@nbd.name>
pex.c

diff --git a/pex.c b/pex.c
index 38d314d0d188827f06d3f776c6b772806af1a494..0e66d24dc58f33b6f7e9723d0296f062d888250d 100644 (file)
--- a/pex.c
+++ b/pex.c
@@ -462,15 +462,17 @@ network_pex_fd_cb(struct uloop_fd *fd, unsigned int events)
 
 int network_pex_open(struct network *net)
 {
-       struct network_peer *local = &net->net_config.local_host->peer;
+       struct network_host *local_host = net->net_config.local_host;
+       struct network_peer *local;
        struct network_pex *pex = &net->pex;
        struct sockaddr_in6 sin6 = {};
        int yes = 1;
        int fd;
 
-       if (!local || !net->net_config.pex_port)
+       if (!local_host || !net->net_config.pex_port)
                return 0;
 
+       local = &local_host->peer;
        fd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
        if (fd < 0)
                return -1;