Received: by 2002:a89:28c:0:b0:1ef:fe5e:92fe with SMTP id j12csp19862lqh; Sun, 17 Mar 2024 19:09:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrp0ubD08J/1U94bnGFt0BpW/IuUfzxXBPP6RJxAQHldZcWerimek0iSgqvM1rN3J3JNyX23zBaHX+aZMCjmA1l5+Cc6IfZbE0nxplNg== X-Google-Smtp-Source: AGHT+IElcIhVJMbfcaaXOxltBvXeAD8lWUrNN80zkjiymCMOWzA7Lua24b3PXx0MVQruu0W3qWwH X-Received: by 2002:a05:6358:7523:b0:17e:cd08:8bc with SMTP id k35-20020a056358752300b0017ecd0808bcmr6238208rwg.20.1710727797060; Sun, 17 Mar 2024 19:09:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710727797; cv=pass; d=google.com; s=arc-20160816; b=VgyP3qVPn85RX7E12OVEF1QHfQNQHC96EOzirdFHScp2D54jD//o5HWG6yvCzDpc4z WWSbz0LAdlYKftFIt4AOaUzOO2wC1SHvCYv5j/DryaIY5aPxIfh75AgYfQjgRCp/Bg1+ ekoo3psd/G8/C/q283SO8eJxuhxZEvsZ6o0d0zazeaT+3p9Zl5QsVVutJGMYoQOGrpRc fSUodFDD4tWKhdbyiEl8Nqpflsdtg48Q0A9T2l2nH2Qfoi4DrywhnlFLAf5QuQXTyKfv rVXdkjjE83SyPqHvPGJ21EaQWDBZ27d9zwVAM/BRRYRPxP4ZcHmibkT1yWsizO0d+0N9 dscQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature:dkim-filter; bh=SIf/+MqbeJUe2PsctvamEzR9L4uheZJqgV8P1Cq6s2c=; fh=HImQGtoZ9j+2GHz3pRSTzkW4Ox84xamL+Ij6VnFicWg=; b=dHGsjZ58/lZJMQ1aiQW7MlEaa7QKVrlWE6Ziiq/wtd9W/i8ONVTWBPoFFKPxKnynV2 NuT6zgmLKW/sLes7ejtPuiasglQpEoXnghfpiSMN8mxyrAgBdSeTaPzdlfotUFfyHGvi CMjUFE45PDi/jIS3cWvZE+qrrGMcWJtJHFirqVS6pIGssvR47nN/Wo0/3eKs44V3yurL 0Dr16LHz11ff2dZLw0+GmArz1ppYO/GQRHoG7N6Dml84+Z59+75ynyunxx97ScLZnzan Kr9zXtaGtee0lh3JU48WREPZ9HL80bfDpkRPOUzPGuiPemlrgWhs9Es925vM7tMIAj7P H1sA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=g7kCyzeB; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-105644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105644-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id z9-20020a631909000000b005dc87643ccdsi7135097pgl.79.2024.03.17.19.09.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 19:09:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-105644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=g7kCyzeB; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-105644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105644-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8BEBAB23A9C for ; Mon, 18 Mar 2024 02:03:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 876EC1E896; Mon, 18 Mar 2024 02:03:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="g7kCyzeB" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4514C1E86A; Mon, 18 Mar 2024 02:03:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710727382; cv=none; b=g+nDhY+Zo7+4tZ7fRGDQWSaVb3WTMgfAYJEHiLo94Cu4QoNJuK7oABUKoY5Mo/ZmVDZYOFQKuwi8Ib9kRWchTxLwAWddniY0nEQZHmiakqnRkQnK4EepId9eti4e0OmZGlpMQZWdVEGYAIUyukESH/KcQ5tZNf/wmEGESN3A9Us= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710727382; c=relaxed/simple; bh=VEV3bHnrvpDLnxzjH5gw8v6jQnwfu7MuGbkOPp9uIZ8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZZTXmqbpXAQDDUsy/HR+JOgB30vxbTFJKHj9F2dgbv7jqNHicngvebD7+/QFS0S7x+IBEkmTiIwlZxjlLJRE2cIo/XuUpZktriz80woH497VFLCV4IPlzx+oUzbAQE8YDvvcWu8+6b9M9yDSnE9UP8BLKAJuUBMruic/XpI+4Us= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=g7kCyzeB; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1134) id D4DB120B74C1; Sun, 17 Mar 2024 19:02:55 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D4DB120B74C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1710727375; bh=SIf/+MqbeJUe2PsctvamEzR9L4uheZJqgV8P1Cq6s2c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=g7kCyzeBH+DU6DesWij01JeVviGKuGmT0n/3kBzEaWiw0jS37RGr01rF0Ib22POFF XMQGugEfO90LOtzOC5xoJ94+tFkYkxuTk6z86G/uXDoeU71mZZ+8gDbTfwcaovuOcB aUIPqVW5sJvIROqXiUEk/60DUD6KR8/9AeXfrqm4= Date: Sun, 17 Mar 2024 19:02:55 -0700 From: Shradha Gupta To: Easwar Hariharan Cc: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Michael Kelley , Olaf Hering , Ani Sinha , Shradha Gupta Subject: Re: [PATCH v2] hv/hv_kvp_daemon: Handle IPv4 and Ipv6 combination for keyfile format Message-ID: <20240318020255.GA28704@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1710247112-7414-1-git-send-email-shradhagupta@linux.microsoft.com> <3bf8844a-3e19-4105-8cce-2b1f8f98d3bc@linux.microsoft.com> <20240313052212.GB22465@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20240315140914.GA14685@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) On Fri, Mar 15, 2024 at 09:56:22AM -0700, Easwar Hariharan wrote: > On 3/15/2024 7:09 AM, Shradha Gupta wrote: > > > > >>>> } > >>>> > >>>> +static int process_dns_gateway_nm(FILE *f, char *ip_string, int type, > >>>> + int ip_sec) > >>>> +{ > >>>> + char addr[INET6_ADDRSTRLEN], *output_str; > >>>> + int ip_offset = 0, error = 0, ip_ver; > >>>> + char *param_name; > >>>> + > >>>> + output_str = (char *)calloc(INET6_ADDRSTRLEN * MAX_IP_ENTRIES, > >>>> + sizeof(char)); > >>>> + > >>>> + if (!output_str) > >>>> + return -ENOMEM; > >>>> + > >>>> + memset(addr, 0, sizeof(addr)); > >>>> + > >>>> + if (type == DNS) { > >>>> + param_name = "dns"; > >>>> + } else if (type == GATEWAY) { > >>>> + param_name = "gateway"; > >>>> + } else { > >>>> + error = -EINVAL; > >>>> + goto cleanup; > >>>> + } > >>>> + > >>>> + while (parse_ip_val_buffer(ip_string, &ip_offset, addr, > >>>> + (MAX_IP_ADDR_SIZE * 2))) { > >>>> + ip_ver = ip_version_check(addr); > >>>> + if (ip_ver < 0) > >>>> + continue; > >>>> + > >>>> + if ((ip_ver == IPV4 && ip_sec == IPV4) || > >>>> + (ip_ver == IPV6 && ip_sec == IPV6)) { > >>>> + if (((INET6_ADDRSTRLEN * MAX_IP_ENTRIES) - strlen(output_str)) > > >>>> + (strlen(addr))) { > >>>> + strcat(output_str, addr); > >>>> + strcat(output_str, ","); > >>> > >>> Prefer strncat() here > > Is this needed with the bound check above. I am trying to keep parity with the rest of the > > file. > >>> > > > I missed this earlier because my comment was more of a general best practice comment. > > Note that in the worst case where your bounds check (INET6_ADDRSTRLEN*MAX_IP_ENTRIES) - strlen(output_str) equals (strlen(addr) + 1), > you will be adding strlen(addr)+1(","), and end up with no ASCII NUL '\0' delimiter. > > If you're going to rely on the bounds check to ensure correctness, you'll need to correct that. Generally speaking, strncat would still > be helpful in case the bounds check changes in the future. > > Thanks, > Easwar got it. Thanks.