Skip to contentSkip to conversation

examples/vm_power_manager: fix string null termination

PATCH Applied Reshma Pattan 3 participants 3 messages Apr 9, 2019 – Apr 22, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/vm_power_manager: fix string null termination

After the read() the jason_data null termination is missing for the case "indent < 0", for "indent > 0" and "indent == 0" cases null termination is already handled.

So add the missing case "indent < 0" to the existing "indent == 0" case to fix null termination.

Coverity issue: 337680

Fixes a63504a90f ("examples/power: add JSON string handling")
---
 examples/vm_power_manager/channel_monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/vm_power_manager/channel_monitor.c +1 -1
index 74df0fe20..c67ca4710 100644
@@ -807,7 +807,7 @@ read_json_packet(struct channel_info *chan_info)
 				indent--;
 			if ((indent > 0) || (idx > 0))
 				idx++;
-			if (indent == 0)
+			if (indent <= 0)
 				json_data[idx] = 0;
 			if (idx >= MAX_JSON_STRING_LEN-1)
 				break;
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · Reshma Pattan

After the read() the jason_data null termination is missing for the case "indent < 0", for "indent > 0" and "indent == 0" cases null termination is already handled.

So add the missing case "indent < 0" to the existing "indent == 0" case to fix null termination.

Coverity issue: 337680

Fixes a63504a90f ("examples/power: add JSON string handling")
---
  examples/vm_power_manager/channel_monitor.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
examples/vm_power_manager/channel_monitor.c +0 -0
index 74df0fe20..c67ca4710 100644

examples/vm_power_manager/channel_monitor.c read_json_packet(struct channel_info *chan_info) · line 813

Quoted 8 lines
examples/vm_power_manager/channel_monitor.c +1 -1
@@ -807,7 +807,7 @@ read_json_packet(struct channel_info *chan_info)
  				indent--;
  			if ((indent > 0) || (idx > 0))
  				idx++;
-			if (indent == 0)
+			if (indent <= 0)
  				json_data[idx] = 0;
  			if (idx >= MAX_JSON_STRING_LEN-1)
  				break;
#2 lore raw

15/04/2019 16:50, Hunt, David:

Quoted 8 lines · Reshma Pattan
Quoted 7 lines

After the read() the jason_data null termination is missing for the case "indent < 0", for "indent > 0" and "indent == 0" cases null termination is already handled.

So add the missing case "indent < 0" to the existing "indent == 0" case to fix null termination.

Quoted 8 lines
Quoted 6 lines

Coverity issue: 337680

Fixes a63504a90f ("examples/power: add JSON string handling")

Applied, thanks