From patchwork Thu Apr 16 17:56:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel M. Weeks" X-Patchwork-Id: 1271833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4936S32cRJz9sWS for ; Fri, 17 Apr 2020 03:59:31 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=rpi.edu Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4936S24rmzzDsGm for ; Fri, 17 Apr 2020 03:59:30 +1000 (AEST) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rpi.edu (client-ip=128.113.2.230; helo=smtp10.server.rpi.edu; envelope-from=weeksd2@rpi.edu; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=rpi.edu Received: from smtp10.server.rpi.edu (smtp10.server.rpi.edu [128.113.2.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4936NC1yX2zDsGh for ; Fri, 17 Apr 2020 03:56:10 +1000 (AEST) Received: from smtp-auth3.server.rpi.edu (route.canit.rpi.edu [128.113.2.233]) by smtp10.server.rpi.edu (8.14.4/8.14.4/Debian-8+deb8u2) with ESMTP id 03GHu5Zc096377 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 16 Apr 2020 13:56:06 -0400 Received: from smtp-auth3.server.rpi.edu (localhost [127.0.0.1]) by smtp-auth3.server.rpi.edu (Postfix) with ESMTP id 2359A58024 for ; Thu, 16 Apr 2020 13:56:05 -0400 (EDT) Received: from dev.danweeks.net (cpe-74-70-107-6.nycap.res.rr.com [74.70.107.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: weeksd2) by smtp-auth3.server.rpi.edu (Postfix) with ESMTPSA id F03CF58008 for ; Thu, 16 Apr 2020 13:56:04 -0400 (EDT) Date: Thu, 16 Apr 2020 13:56:00 -0400 From: "Daniel M. Weeks" To: petitboot@lists.ozlabs.org Subject: [PATCH 09/11] Use hwaddr_len over sizeof hwaddr Message-ID: <492d4efdba3eaf9edbac5218f83367658238ba81.1587059210.git.weeksd2@rpi.edu> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Virus-Scanned: ClamAV using ClamSMTP X-Bayes-Prob: 0.0001 (Score 0, tokens from: outgoing, @@RPTN) X-Spam-Score: 0.00 () [Hold at 10.10] X-CanIt-Incident-Id: 032rtU5G2 X-CanIt-Geo: ip=74.70.107.6; country=US; region=New York; city=Troy; latitude=42.7273; longitude=-73.6696; http://maps.google.com/maps?q=42.7273,-73.6696&z=6 X-CanItPRO-Stream: outgoing X-Canit-Stats-ID: Bayes signature not available X-Scanned-By: CanIt (www . roaringpenguin . com) on 128.113.2.230 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" The length of the hardware address stored in hwaddr may be shorter than the size of the field. Only the actual length should be used in comparisons and transformations of hwaddr. Signed-off-by: Daniel M. Weeks --- discover/network.c | 25 +++++++++++++------------ discover/platform-powerpc.c | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/discover/network.c b/discover/network.c index 0433c70..8637fc8 100644 --- a/discover/network.c +++ b/discover/network.c @@ -89,7 +89,7 @@ static char *mac_bytes_to_string(void *ctx, uint8_t *addr, int len) } static const struct interface_config *find_config_by_hwaddr( - uint8_t *hwaddr) + uint8_t *hwaddr, int hwaddr_len) { const struct config *config; unsigned int i; @@ -140,7 +140,7 @@ static struct interface *find_interface_by_uuid(struct network *network, list_for_each_entry(&network->interfaces, interface, list) { mac = mac_bytes_to_string(interface, interface->hwaddr, - sizeof(interface->hwaddr)); + interface->hwaddr_len); if (!strcmp(mac, uuid)) { talloc_free(mac); return interface; @@ -161,7 +161,7 @@ uint8_t *find_mac_by_name(void *ctx, struct network *network, return NULL; return talloc_memdup(ctx, &interface->hwaddr, - sizeof(uint8_t) * HWADDR_SIZE); + interface->hwaddr_len); } static int network_init_netlink(struct network *network) @@ -221,7 +221,7 @@ static void create_interface_dev(struct network *network, struct interface *interface) { char *uuid = mac_bytes_to_string(interface, interface->hwaddr, - sizeof(interface->hwaddr)); + interface->hwaddr_len); interface->dev = discover_device_create(network->handler, uuid, interface->name); @@ -253,7 +253,7 @@ void network_register_device(struct network *network, iface->dev = dev; dev->uuid = mac_bytes_to_string(iface->dev, iface->hwaddr, - sizeof(iface->hwaddr)); + iface->hwaddr_len); } void network_unregister_device(struct network *network, @@ -390,7 +390,7 @@ static void configure_interface_static(struct network *network, return; } - system_info_set_interface_address(sizeof(interface->hwaddr), + system_info_set_interface_address(interface->hwaddr_len, interface->hwaddr, config->static_config.address); @@ -417,7 +417,7 @@ static void configure_interface_static(struct network *network, config->static_config.url, mac_bytes_to_string(interface->dev, interface->hwaddr, - sizeof(interface->hwaddr)), + interface->hwaddr_len), config->static_config.address); device_handler_start_requery_timeout(network->handler, interface->dev, -1); @@ -455,7 +455,8 @@ static void configure_interface(struct network *network, return; } - config = find_config_by_hwaddr(interface->hwaddr); + config = find_config_by_hwaddr(interface->hwaddr, interface->hwaddr_len); + if (config && config->ignore) { pb_log("network: ignoring interface %s\n", interface->name); interface->state = IFSTATE_IGNORED; @@ -521,7 +522,7 @@ void network_requery_device(struct network *network, process_release(interface->udhcpc_process); } - config = find_config_by_hwaddr(interface->hwaddr); + config = find_config_by_hwaddr(interface->hwaddr, interface->hwaddr_len); if (config && config->ignore) return; @@ -540,7 +541,7 @@ void network_requery_device(struct network *network, config->static_config.url, mac_bytes_to_string(interface->dev, interface->hwaddr, - sizeof(interface->hwaddr)), + interface->hwaddr_len), config->static_config.address); device_handler_start_requery_timeout(network->handler, dev, -1); @@ -613,7 +614,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) interface = talloc_zero(network, struct interface); interface->ifindex = info->ifi_index; interface->state = IFSTATE_NEW; - memcpy(interface->hwaddr, ifaddr, sizeof(interface->hwaddr)); + memcpy(interface->hwaddr, ifaddr, interface->hwaddr_len); strncpy(interface->name, ifname, sizeof(interface->name) - 1); list_for_each_entry(&network->interfaces, tmp, list) @@ -641,7 +642,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) /* notify the sysinfo code about changes to this interface */ if (strcmp(interface->name, "lo")) system_info_register_interface( - sizeof(interface->hwaddr), + interface->hwaddr_len, interface->hwaddr, interface->name, info->ifi_flags & IFF_LOWER_UP); diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index be2fbab..9bdba30 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -261,14 +261,14 @@ static void set_param(struct platform_powerpc *platform, const char *name, static int parse_hwaddr(struct interface_config *ifconf, char *str) { - int i; + unsigned int i; if (strlen(str) != strlen("00:00:00:00:00:00")) return -1; ifconf->hwaddr_len = strlen(str) / 3 + 1; - for (i = 0; i < HWADDR_SIZE; i++) { + for (i = 0; i < ifconf->hwaddr_len; i++) { char byte[3], *endp; unsigned long x;