Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp928789lqb; Fri, 15 Mar 2024 10:06:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKWoe+V2bWQ27u4DLbx5U8KlgxKOBhLGm0X5hw1y5AUK8K1DmBOMHrvo20DXJcLYeuQKbKXjGLUqd2nqcggdMYHCusmMeJu050SlVU0w== X-Google-Smtp-Source: AGHT+IHONfurdC2zGyro9VaKBjGQeRxTiZMLkTqOS98CCg7G6TswcI+3y5RPWozTIRUqfu7M+O+T X-Received: by 2002:a05:6e02:ed0:b0:366:2d4f:9390 with SMTP id i16-20020a056e020ed000b003662d4f9390mr5174145ilk.8.1710522387069; Fri, 15 Mar 2024 10:06:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710522387; cv=pass; d=google.com; s=arc-20160816; b=v7LfDzgQLm/xrGibAubYS1TFHj/K9eOchK7fRY1/L+Pmj6r003LeA8P8LBo+we/XDP HxOzbuiGcghh/j34QXmoX0dWfIN0l9/hoM9hbl0Q+ROr1ef/qnMVz2BPN7XfHuP3p3LR SX/kYznjlpon9qrgRRRygIaEAENKMNGBbQ8rgO//3SSjj+pmDIr1IDXGSUeywcbjD3cG yCfJ0dTbQVlMQVEVLSFdAAoh8BZxOCIAq/MLl8Z0JoOX/UD9/Od7VUrWpXoV8SrV8G8r aRrKrW6/QvTavGsq0Jt9DvKqI+PYQDpd7KjNg8Wdp5acmppTkUU5cHQeu+URwQ/yPSKx yC1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-filter; bh=Q78OTWOsVRBCL80yDDNEfCI9drv9glFw8Ky35vj5BKY=; fh=IQU6lsUgCikTo6I5COHsa3eshUNNmKCXqwo5yiUo4eE=; b=ptxH50nTulcerHRrTxpDWXot/5CBaRq8ZwtMSm58O6DfeDq6GkXArUUY69k/f8aZBn uBok/Txx/O8aPvBEZdgqbEy6zSWx/nKiqieaQ051kSEQ3Zyil9n9miTxDssfekr09LP0 hv/hmDzvTmHVrqocTwo79vh0GKvmzuxcbVNQRw6s31sKn1YF+lu6j0bOsdReh8cbPfEW /ltUDcMFHMtNbwohMXrLxt3qPop/bQutzKzsMvXny7AqK/CCSwYc7SR4K5K84mfXiC+Z +bpDitz7qlENxiGs5tYZe3nV5lHVM8zJIqbFJNuN86zbZGC4DUD4fxg7RJp9AxVlABUP BqnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=rSVsPH7E; 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-104682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104682-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 sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p3-20020a63ab03000000b005df42c5313bsi3112287pgf.16.2024.03.15.10.06.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 10:06:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=rSVsPH7E; 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-104682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104682-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B4589283EBF for ; Fri, 15 Mar 2024 17:06:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D64FF4F5FB; Fri, 15 Mar 2024 16:56:26 +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="rSVsPH7E" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 905B34779D; Fri, 15 Mar 2024 16:56:24 +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=1710521786; cv=none; b=aDPC6G3iSfYofL9jA+mzqfI7jljOgTErZAjld7LW5U9ugZPmfkcn1W3Brx+OSCrTmd6BdDS1TkDsm0AmBSR8eh0NziPZz+WPW7RT0R+HSQeLiejMc2/iRplgMUhQ0FQFdZVYbhxu+a/Icf4xWgrEbxJbzJ1cnSpsAa87AWcIcP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521786; c=relaxed/simple; bh=WdvwjxQVySFmsU+ux3dQqefsmL5GQWcxrNM2Du895kc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=a6IxaoSCqFOFu2m3zD8NZRsvorUhtNTc1R9bRksb62NrOifANd0GbHssTPElK6XSK09keYeRMQAN1vbRDN9MwckJjuuq+mTV/f4Y/9tMGgdfbAWayn463bYXDjVNsFQKodEV+e3MI0XELFzs1ASb25DFVgob3/73VZkHxoCTiJM= 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=rSVsPH7E; 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: from [100.64.232.154] (unknown [20.29.225.195]) by linux.microsoft.com (Postfix) with ESMTPSA id BC5F720B74C0; Fri, 15 Mar 2024 09:56:23 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BC5F720B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1710521784; bh=Q78OTWOsVRBCL80yDDNEfCI9drv9glFw8Ky35vj5BKY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=rSVsPH7E852ccfLCYlhbYQV4XdBIIohLhdPGxy7GYa1OsmerTjMJ6iRldg68M1qGO ltnxyOb7WP0YoJpudcR8fzqrgqAn5uWI+D4MCOTe+3WsCOJ5sxU3WKymHt6nSsZGix FinTjVTBGNmicQoaWhzqdLggvo6NdU2UjcnyU7G0= Message-ID: Date: Fri, 15 Mar 2024 09:56:22 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] hv/hv_kvp_daemon: Handle IPv4 and Ipv6 combination for keyfile format To: Shradha Gupta 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 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> Content-Language: en-CA From: Easwar Hariharan In-Reply-To: <20240315140914.GA14685@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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