From f46577a8945563c54f5bf0fdc293de4f2f05495e Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 26 Aug 2024 06:04:24 +0000 Subject: [PATCH] Be stricter in what we accept from the main process. While here mention function where fatalx(3) occurred like everywhere else. Suggested by & OK tb --- sbin/dhcpleased/engine.c | 23 ++++++++++++++++------- sbin/dhcpleased/frontend.c | 23 ++++++++++++++++------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/sbin/dhcpleased/engine.c b/sbin/dhcpleased/engine.c index cdb06545b20..82c7793c473 100644 --- a/sbin/dhcpleased/engine.c +++ b/sbin/dhcpleased/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.46 2024/08/25 09:53:53 florian Exp $ */ +/* $OpenBSD: engine.c,v 1.47 2024/08/26 06:04:24 florian Exp $ */ /* * Copyright (c) 2017, 2021 Florian Obser @@ -493,8 +493,11 @@ engine_dispatch_main(int fd, short event, void *bula) break; case IMSG_RECONF_VC_ID: if (iface_conf == NULL) - fatalx("IMSG_RECONF_VC_ID without " - "IMSG_RECONF_IFACE"); + fatalx("%s: %s without IMSG_RECONF_IFACE", + __func__, i2s(type)); + if (iface_conf->vc_id != NULL) + fatalx("%s: multiple %s for the same interface", + __func__, i2s(type)); if ((iface_conf->vc_id_len = imsg_get_len(&imsg)) > 255 + 2 || iface_conf->vc_id_len == 0) fatalx("%s: invalid %s", __func__, i2s(type)); @@ -507,8 +510,11 @@ engine_dispatch_main(int fd, short event, void *bula) break; case IMSG_RECONF_C_ID: if (iface_conf == NULL) - fatalx("IMSG_RECONF_C_ID without " - "IMSG_RECONF_IFACE"); + fatalx("%s: %s without IMSG_RECONF_IFACE", + __func__, i2s(type)); + if (iface_conf->c_id != NULL) + fatalx("%s: multiple %s for the same interface", + __func__, i2s(type)); if ((iface_conf->c_id_len = imsg_get_len(&imsg)) > 255 + 2 || iface_conf->c_id_len == 0) fatalx("%s: invalid %s", __func__, i2s(type)); @@ -523,8 +529,11 @@ engine_dispatch_main(int fd, short event, void *bula) size_t len; if (iface_conf == NULL) - fatalx("IMSG_RECONF_H_NAME without " - "IMSG_RECONF_IFACE"); + fatalx("%s: %s without IMSG_RECONF_IFACE", + __func__, i2s(type)); + if (iface_conf->h_name != NULL) + fatalx("%s: multiple %s for the same interface", + __func__, i2s(type)); if ((len = imsg_get_len(&imsg)) > 256 || len == 0) fatalx("%s: invalid %s", __func__, i2s(type)); if ((iface_conf->h_name = malloc(len)) == NULL) diff --git a/sbin/dhcpleased/frontend.c b/sbin/dhcpleased/frontend.c index ddb72eb4b4f..d0dae2d7a74 100644 --- a/sbin/dhcpleased/frontend.c +++ b/sbin/dhcpleased/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.36 2024/08/25 09:53:53 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.37 2024/08/26 06:04:24 florian Exp $ */ /* * Copyright (c) 2017, 2021 Florian Obser @@ -369,8 +369,11 @@ frontend_dispatch_main(int fd, short event, void *bula) break; case IMSG_RECONF_VC_ID: if (iface_conf == NULL) - fatalx("IMSG_RECONF_VC_ID without " - "IMSG_RECONF_IFACE"); + fatalx("%s: %s without IMSG_RECONF_IFACE", + __func__, i2s(type)); + if (iface_conf->vc_id != NULL) + fatalx("%s: multiple %s for the same interface", + __func__, i2s(type)); if ((iface_conf->vc_id_len = imsg_get_len(&imsg)) > 255 + 2 || iface_conf->vc_id_len == 0) fatalx("%s: invalid %s", __func__, i2s(type)); @@ -383,8 +386,11 @@ frontend_dispatch_main(int fd, short event, void *bula) break; case IMSG_RECONF_C_ID: if (iface_conf == NULL) - fatalx("IMSG_RECONF_C_ID without " - "IMSG_RECONF_IFACE"); + fatalx("%s: %s without IMSG_RECONF_IFACE", + __func__, i2s(type)); + if (iface_conf->c_id != NULL) + fatalx("%s: multiple %s for the same interface", + __func__, i2s(type)); if ((iface_conf->c_id_len = imsg_get_len(&imsg)) > 255 + 2 || iface_conf->c_id_len == 0) fatalx("%s: invalid %s", __func__, i2s(type)); @@ -399,8 +405,11 @@ frontend_dispatch_main(int fd, short event, void *bula) size_t len; if (iface_conf == NULL) - fatalx("IMSG_RECONF_H_NAME without " - "IMSG_RECONF_IFACE"); + fatalx("%s: %s without IMSG_RECONF_IFACE", + __func__, i2s(type)); + if (iface_conf->h_name != NULL) + fatalx("%s: multiple %s for the same interface", + __func__, i2s(type)); if ((len = imsg_get_len(&imsg)) > 256 || len == 0) fatalx("%s: invalid %s", __func__, i2s(type)); if ((iface_conf->h_name = malloc(len)) == NULL) -- 2.20.1