DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: David Hunt <david.hunt@intel.com>, dev@dpdk.org, stable@dpdk.org
Subject: Re: [dpdk-dev] [PATCH v2] examples/vm_power_manager: fix string null termination
Date: Fri, 26 Apr 2019 13:47:41 +0100	[thread overview]
Message-ID: <adc81ddc-a1f6-d651-a785-e1f9f2c8372c@intel.com> (raw)
Message-ID: <20190426124741.eK42r1P4C_8b5KaTpiQnEVNiHhpIcME1CGjeGegf6hA@z> (raw)
In-Reply-To: <20190426123117.GA1695@bricha3-MOBL.ger.corp.intel.com>

On 26-Apr-19 1:31 PM, Bruce Richardson wrote:
> On Fri, Apr 26, 2019 at 12:56:08PM +0100, Burakov, Anatoly wrote:
>> 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 <david.hunt@intel.com>
>>>
>>> ---
>>> 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.
>>
> +1 to that.
> 
> An alternative and simpler option might be to memset the who array to zero
> before you start anyway.

That'll cost us few extra cycles on a non-performance critical path full 
of syscalls, surely we can't have that! :)

> 
> /Bruce
> 


-- 
Thanks,
Anatoly

  parent reply	other threads:[~2019-04-26 12:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-26  8:43 [dpdk-dev] [PATCH v1] " David Hunt
2019-04-26  8:43 ` David Hunt
2019-04-26 10:33 ` Burakov, Anatoly
2019-04-26 10:33   ` Burakov, Anatoly
2019-04-26 11:16   ` Hunt, David
2019-04-26 11:16     ` Hunt, David
2019-04-26 11:24 ` [dpdk-dev] [PATCH v2] " David Hunt
2019-04-26 11:24   ` David Hunt
2019-04-26 11:56   ` Burakov, Anatoly
2019-04-26 11:56     ` Burakov, Anatoly
2019-04-26 12:31     ` Bruce Richardson
2019-04-26 12:31       ` Bruce Richardson
2019-04-26 12:47       ` Burakov, Anatoly [this message]
2019-04-26 12:47         ` Burakov, Anatoly
2019-04-26 14:04   ` [dpdk-dev] [PATCH v3] " David Hunt
2019-04-26 14:04     ` David Hunt
2019-04-26 14:10     ` Burakov, Anatoly
2019-04-26 14:10       ` Burakov, Anatoly
2019-05-02 23:43       ` Thomas Monjalon
2019-05-02 23:43         ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=adc81ddc-a1f6-d651-a785-e1f9f2c8372c@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).