[v3] examples/vm_power_manager: fix string null termination

Message ID 20190426140454.29684-1-david.hunt@intel.com (mailing list archive)
State Accepted, archived
Headers
Series [v3] examples/vm_power_manager: fix string null termination |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Hunt, David April 26, 2019, 2:04 p.m. UTC
  coverity complains about a null-termination after a read,
so we terminate once we exit the do-while read loop.

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.
v3: Simplify null termimation
---
 examples/vm_power_manager/channel_monitor.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
  

Comments

Anatoly Burakov April 26, 2019, 2:10 p.m. UTC | #1
On 26-Apr-19 3:04 PM, David Hunt wrote:
> coverity complains about a null-termination after a read,
> so we terminate once we exit the do-while read loop.
> 
> 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.
> v3: Simplify null termimation
> ---
>   examples/vm_power_manager/channel_monitor.c | 7 +------
>   1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
> index 971e4f2bc..4a287109b 100644
> --- a/examples/vm_power_manager/channel_monitor.c
> +++ b/examples/vm_power_manager/channel_monitor.c
> @@ -822,12 +822,7 @@ read_json_packet(struct channel_info *chan_info)
>   				break;
>   		} while (indent > 0);
>   
> -		if (indent > 0)
> -			/*
> -			 * We've broken out of the read loop without getting
> -			 * a closing brace, so throw away the data
> -			 */
> -			json_data[idx] = 0;
> +		json_data[idx] = '\0';
>   
>   		if (strlen(json_data) == 0)
>   			continue;
> 

Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
Thomas Monjalon May 2, 2019, 11:43 p.m. UTC | #2
26/04/2019 16:10, Burakov, Anatoly:
> On 26-Apr-19 3:04 PM, David Hunt wrote:
> > coverity complains about a null-termination after a read,
> > so we terminate once we exit the do-while read loop.
> > 
> > Coverity issue: 337680
> > Fixes: a63504a90f ("examples/power: add JSON string handling")
> > CC: stable@dpdk.org
> > 
> > Signed-off-by: David Hunt <david.hunt@intel.com>
> 
> Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks

PS: replaced "string" with "json" in title to give a bit more context.
  

Patch

diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
index 971e4f2bc..4a287109b 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -822,12 +822,7 @@  read_json_packet(struct channel_info *chan_info)
 				break;
 		} while (indent > 0);
 
-		if (indent > 0)
-			/*
-			 * We've broken out of the read loop without getting
-			 * a closing brace, so throw away the data
-			 */
-			json_data[idx] = 0;
+		json_data[idx] = '\0';
 
 		if (strlen(json_data) == 0)
 			continue;