fix build errors when built against glibc
authorFelix Fietkau <nbd@nbd.name>
Thu, 25 Aug 2022 10:16:31 +0000 (12:16 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 25 Aug 2022 10:16:31 +0000 (12:16 +0200)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
main.c
network.c
pex-msg.c

diff --git a/main.c b/main.c
index 9926ecdc3e47e821632dd00e49b93ddc69e1256d..e4e93317fcfe212a5c02b46a81eb73f03f231525 100644 (file)
--- a/main.c
+++ b/main.c
@@ -48,7 +48,9 @@ void unetd_write_hosts(void)
        if (!hosts_file)
                return;
 
-       asprintf(&tmpfile, "%s.XXXXXXXX", hosts_file);
+       if (asprintf(&tmpfile, "%s.XXXXXXXX", hosts_file) < 0)
+               return;
+
        fd = mkstemp(tmpfile);
        if (fd < 0) {
                perror("mkstemp");
index 60426520f7cc4a922acaead2ab19ed8c977caf17..b39deb4c8f1c6733f843092dbba8f28e001cb635 100644 (file)
--- a/network.c
+++ b/network.c
@@ -2,6 +2,7 @@
 /*
  * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
  */
+#define _GNU_SOURCE
 #include <arpa/inet.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -127,7 +128,9 @@ static int network_load_dynamic(struct network *net)
        FILE *f = NULL;
        int ret = -1;
 
-       asprintf(&fname, "%s/%s.bin", data_dir, network_name(net));
+       if (asprintf(&fname, "%s/%s.bin", data_dir, network_name(net)) < 0)
+               return -1;
+
        f = fopen(fname, "r");
        free(fname);
 
@@ -174,7 +177,9 @@ int network_save_dynamic(struct network *net)
            !net->net_data_len)
                return -1;
 
-       asprintf(&fname, "%s/%s.bin.XXXXXXXX", data_dir, network_name(net));
+       if (asprintf(&fname, "%s/%s.bin.XXXXXXXX", data_dir, network_name(net)) < 0)
+               return -1;
+
        fd = mkstemp(fname);
        if (fd < 0)
                goto error;
index 16c1acb15af9553482c4c9b021e8f37b42238fa2..22825be1d552738ad2552455a57d4a26bac61f77 100644 (file)
--- a/pex-msg.c
+++ b/pex-msg.c
@@ -77,7 +77,8 @@ struct pex_hdr *__pex_msg_init_ext(const uint8_t *pubkey, const uint8_t *auth_ke
 
        hdr->len = sizeof(*ehdr);
 
-       fread(&ehdr->nonce, sizeof(ehdr->nonce), 1, pex_urandom);
+       if (fread(&ehdr->nonce, sizeof(ehdr->nonce), 1, pex_urandom) != 1)
+               return NULL;
 
        hash = pex_network_hash(auth_key, ehdr->nonce);
        *(uint64_t *)hdr->id ^= hash;
@@ -197,12 +198,16 @@ void pex_msg_update_response_init(struct pex_msg_update_send_ctx *ctx,
        ctx->ext = ext;
        ctx->req_id = req->req_id;
 
-       __pex_msg_init_ext(pubkey, auth_key, PEX_MSG_UPDATE_RESPONSE, ext);
+       if (!__pex_msg_init_ext(pubkey, auth_key, PEX_MSG_UPDATE_RESPONSE, ext))
+               return;
+
        res = pex_msg_append(sizeof(*res));
        res->req_id = req->req_id;
        res->data_len = len;
 
-       fread(e_key_priv, sizeof(e_key_priv), 1, pex_urandom);
+       if (!fread(e_key_priv, sizeof(e_key_priv), 1, pex_urandom))
+               return;
+
        curve25519_clamp_secret(e_key_priv);
        curve25519_generate_public(res->e_key, e_key_priv);
        curve25519(enc_key, e_key_priv, peer_key);
@@ -227,8 +232,10 @@ bool pex_msg_update_response_continue(struct pex_msg_update_send_ctx *ctx)
                return false;
        }
 
-       __pex_msg_init_ext(ctx->pubkey, ctx->auth_key,
-                          PEX_MSG_UPDATE_RESPONSE_DATA, ctx->ext);
+       if (!__pex_msg_init_ext(ctx->pubkey, ctx->auth_key,
+                               PEX_MSG_UPDATE_RESPONSE_DATA, ctx->ext))
+               return false;
+
        res_ext = pex_msg_append(sizeof(*res_ext));
        res_ext->req_id = ctx->req_id;
        res_ext->offset = ctx->cur - ctx->data;
@@ -255,12 +262,17 @@ pex_msg_update_request_init(const uint8_t *pubkey, const uint8_t *priv_key,
        memcpy(&ctx->addr, addr, sizeof(ctx->addr));
        memcpy(ctx->auth_key, auth_key, sizeof(ctx->auth_key));
        memcpy(ctx->priv_key, priv_key, sizeof(ctx->priv_key));
-       fread(&ctx->req_id, sizeof(ctx->req_id), 1, pex_urandom);
+       if (!fread(&ctx->req_id, sizeof(ctx->req_id), 1, pex_urandom))
+               return NULL;
        list_add_tail(&ctx->list, &requests);
        if (!gc_timer.pending)
                uloop_timeout_set(&gc_timer, 1000);
 
-       __pex_msg_init_ext(pubkey, auth_key, PEX_MSG_UPDATE_REQUEST, ext);
+       if (!__pex_msg_init_ext(pubkey, auth_key, PEX_MSG_UPDATE_REQUEST, ext)) {
+               free(ctx);
+               return NULL;
+       }
+
        req = pex_msg_append(sizeof(*req));
        req->cur_version = cpu_to_be64(cur_version);
        req->req_id = ctx->req_id;