From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D233C43219 for ; Fri, 26 Apr 2019 11:56:15 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id EE5C5206C1 for ; Fri, 26 Apr 2019 11:56:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE5C5206C1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 897B31B616; Fri, 26 Apr 2019 13:56:13 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 4132A1B184; Fri, 26 Apr 2019 13:56:12 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2019 04:56:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,397,1549958400"; d="scan'208";a="153965215" Received: from aburakov-mobl1.ger.corp.intel.com (HELO [10.251.92.20]) ([10.251.92.20]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2019 04:56:09 -0700 To: David Hunt , dev@dpdk.org Cc: stable@dpdk.org References: <20190426084337.3921-1-david.hunt@intel.com> <20190426112422.15719-1-david.hunt@intel.com> From: "Burakov, Anatoly" Message-ID: <339cb6ac-9c56-b9cb-28e8-950ad2cd70b4@intel.com> Date: Fri, 26 Apr 2019 12:56:08 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190426112422.15719-1-david.hunt@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v2] examples/vm_power_manager: fix string null termination X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 26-Apr-19 12:24 PM, David Hunt wrote: > coverity complains about a null-termination after a read, > so we terminate after exiting the do-while loop. The position > is conditional on whether idx is within the buffer or at the > end of the buffer. > > Coverity issue: 337680 > Fixes: a63504a90f ("examples/power: add JSON string handling") > CC: stable@dpdk.org > > Signed-off-by: David Hunt > > --- > v2: > * Move null termination outside of do-while. > --- > examples/vm_power_manager/channel_monitor.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c > index 971e4f2bc..03fdcd15a 100644 > --- a/examples/vm_power_manager/channel_monitor.c > +++ b/examples/vm_power_manager/channel_monitor.c > @@ -822,6 +822,8 @@ read_json_packet(struct channel_info *chan_info) > break; > } while (indent > 0); > > + json_data[idx + (idx < MAX_JSON_STRING_LEN - 1)] = '\0'; > + I don't think you need this complicated logic here. You start at idx = 0, so even if you receive 0 bytes, you'll terminate buffer at index 0. You also break when idx reaches (MAX_JSON_STRING_LEN - 1), so it's also safe to do json_data[idx] after the loop. In all other cases, you still increment idx before breaking out (e.g. when reaching indent == 0), so it's also safe to do json_data[idx] in those cases. > if (indent > 0) > /* > * We've broken out of the read loop without getting > -- Thanks, Anatoly