From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 9D70A1B600; Fri, 26 Apr 2019 13:16:26 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2019 04:16:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,397,1549958400"; d="scan'208";a="294745200" Received: from dhunt5-mobl2.ger.corp.intel.com (HELO [10.237.210.15]) ([10.237.210.15]) by orsmga004.jf.intel.com with ESMTP; 26 Apr 2019 04:16:24 -0700 To: "Burakov, Anatoly" , dev@dpdk.org Cc: stable@dpdk.org References: <20190426084337.3921-1-david.hunt@intel.com> <46433916-0e77-fd36-94fc-0cb855fac3b9@intel.com> From: "Hunt, David" Message-ID: <9cba436d-14e7-21c3-96fb-85c9ac6ba8ec@intel.com> Date: Fri, 26 Apr 2019 12:16:23 +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: <46433916-0e77-fd36-94fc-0cb855fac3b9@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [dpdk-dev] [PATCH v1] 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: , X-List-Received-Date: Fri, 26 Apr 2019 11:16:27 -0000 Hi Anatoly, On 26/4/2019 11:33 AM, Burakov, Anatoly wrote: > On 26-Apr-19 9:43 AM, David Hunt wrote: >> coverity complains about a null-termination after a read, >> so we terminate conditionally 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 >> --- >>   examples/vm_power_manager/channel_monitor.c | 1 + >>   1 file changed, 1 insertion(+) >> >> diff --git a/examples/vm_power_manager/channel_monitor.c >> b/examples/vm_power_manager/channel_monitor.c >> index 971e4f2bc..711722fef 100644 >> --- a/examples/vm_power_manager/channel_monitor.c >> +++ b/examples/vm_power_manager/channel_monitor.c >> @@ -808,6 +808,7 @@ read_json_packet(struct channel_info *chan_info) >>           int indent = 0; >>           do { >>               n_bytes = read(chan_info->fd, &json_data[idx], 1); >> +            json_data[idx + (idx < MAX_JSON_STRING_LEN - 1)] = '\0'; > > Why do it inside the loop and not after? > No reason, really. I'll move it outside and re-spin. >>               if (n_bytes == 0) >>                   break; >>               if (json_data[idx] == '{') >> > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id CA835A05D3 for ; Fri, 26 Apr 2019 13:16:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A04241B617; Fri, 26 Apr 2019 13:16:28 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 9D70A1B600; Fri, 26 Apr 2019 13:16:26 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2019 04:16:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,397,1549958400"; d="scan'208";a="294745200" Received: from dhunt5-mobl2.ger.corp.intel.com (HELO [10.237.210.15]) ([10.237.210.15]) by orsmga004.jf.intel.com with ESMTP; 26 Apr 2019 04:16:24 -0700 To: "Burakov, Anatoly" , dev@dpdk.org Cc: stable@dpdk.org References: <20190426084337.3921-1-david.hunt@intel.com> <46433916-0e77-fd36-94fc-0cb855fac3b9@intel.com> From: "Hunt, David" Message-ID: <9cba436d-14e7-21c3-96fb-85c9ac6ba8ec@intel.com> Date: Fri, 26 Apr 2019 12:16:23 +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: <46433916-0e77-fd36-94fc-0cb855fac3b9@intel.com> Content-Type: text/plain; charset="UTF-8"; format="flowed" Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [dpdk-dev] [PATCH v1] 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" Message-ID: <20190426111623.e2j_5GaEkYmr1OyT324QYqLLtaMY3W4qwCN4zdud_vw@z> Hi Anatoly, On 26/4/2019 11:33 AM, Burakov, Anatoly wrote: > On 26-Apr-19 9:43 AM, David Hunt wrote: >> coverity complains about a null-termination after a read, >> so we terminate conditionally 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 >> --- >>   examples/vm_power_manager/channel_monitor.c | 1 + >>   1 file changed, 1 insertion(+) >> >> diff --git a/examples/vm_power_manager/channel_monitor.c >> b/examples/vm_power_manager/channel_monitor.c >> index 971e4f2bc..711722fef 100644 >> --- a/examples/vm_power_manager/channel_monitor.c >> +++ b/examples/vm_power_manager/channel_monitor.c >> @@ -808,6 +808,7 @@ read_json_packet(struct channel_info *chan_info) >>           int indent = 0; >>           do { >>               n_bytes = read(chan_info->fd, &json_data[idx], 1); >> +            json_data[idx + (idx < MAX_JSON_STRING_LEN - 1)] = '\0'; > > Why do it inside the loop and not after? > No reason, really. I'll move it outside and re-spin. >>               if (n_bytes == 0) >>                   break; >>               if (json_data[idx] == '{') >> > >