commit 6e0942f6979a3751280659736d0c8252253c6136 from: Omar Polo date: Fri Nov 17 09:42:25 2023 UTC gotwebd: inline and remove IMSG_SIZE_CHECK() I always find confusing if IMSG_SIZE_CHECK() takes pointers or not, and we had at least a few instances of wrong usages, so inline (with exact size checks) and remove the macro. ok stsp@ commit - 1632f50aca5cd94ed681c20fc18c2b8ab4857b9c commit + 6e0942f6979a3751280659736d0c8252253c6136 blob - b1108c45d826da11c2d77f4d5c684f9c629ea7c8 blob + bde889cb381f5d8e90f44b27a11986e29f2f27d2 --- gotwebd/config.c +++ gotwebd/config.c @@ -82,7 +82,8 @@ config_getserver(struct gotwebd *env, struct imsg *ims if (srv == NULL) fatalx("%s: calloc", __func__); - IMSG_SIZE_CHECK(imsg, srv); + if (IMSG_DATA_SIZE(imsg) != sizeof(*srv)) + fatalx("%s: wrong size", __func__); memcpy(srv, p, sizeof(*srv)); @@ -119,7 +120,9 @@ config_getsock(struct gotwebd *env, struct imsg *imsg) uint8_t *p = imsg->data; int i; - IMSG_SIZE_CHECK(imsg, &sock_conf); + if (IMSG_DATA_SIZE(imsg) != sizeof(sock_conf)) + fatalx("%s: wrong size", __func__); + memcpy(&sock_conf, p, sizeof(sock_conf)); if (IMSG_DATA_SIZE(imsg) != sizeof(sock_conf)) { @@ -194,7 +197,9 @@ config_getfd(struct gotwebd *env, struct imsg *imsg) uint8_t *p = imsg->data; int sock_id, match = 0, i; - IMSG_SIZE_CHECK(imsg, &sock_id); + if (IMSG_DATA_SIZE(imsg) != sizeof(sock_id)) + fatalx("%s: wrong size", __func__); + memcpy(&sock_id, p, sizeof(sock_id)); TAILQ_FOREACH(sock, &env->sockets, entry) { blob - 71b34a0258f2a201a28b0745032caf69c7fcd5e6 blob + 8005d4db4e8e1da67b226c26b8e1640b5c42645d --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -137,11 +137,6 @@ struct imsgev { short events; }; -#define IMSG_SIZE_CHECK(imsg, p) do { \ - if (IMSG_DATA_SIZE(imsg) < sizeof(*p)) \ - fatalx("bad length imsg received (%s)", #p); \ -} while (0) - #define IMSG_DATA_SIZE(imsg) ((imsg)->hdr.len - IMSG_HEADER_SIZE) struct env_val {