You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2026/10/23 22:02:21 UTC
(mynewt-newtmgr) 15/20: newtmgr/cli: Fix panic on a lone double quote resource value
This is an automated email from the ASF dual-hosted git repository.
sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git
commit 6ce79d255e7161f495f6e73aa2597ebbea177079
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Thu Oct 22 00:23:22 2026 +0200
newtmgr/cli: Fix panic on a lone double quote resource value
extractResKv() treats a value that starts and ends with '"' as a
quoted string and strips the quotes. A value consisting of a single
'"' matched both checks, and slicing [1:0] panicked. For example
newtmgr res put /r 'a="' crashed with "slice bounds out of range"
instead of sending the string. Require at least two characters
before treating a value as quoted, so a lone quote is sent as-is.
Assisted-by: Claude:claude-opus-5-5
---
newtmgr/cli/res.go | 3 ++-
newtmgr/cli/res_test.go | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/newtmgr/cli/res.go b/newtmgr/cli/res.go
index 7205be3..7b75e5b 100644
--- a/newtmgr/cli/res.go
+++ b/newtmgr/cli/res.go
@@ -81,7 +81,8 @@ func extractResKv(params []string) (map[string]interface{}, error) {
var val interface{}
// If value is quoted, parse it as a string.
- if strings.HasPrefix(parts[1], "\"") &&
+ if len(parts[1]) >= 2 &&
+ strings.HasPrefix(parts[1], "\"") &&
strings.HasSuffix(parts[1], "\"") {
val = parts[1][1 : len(parts[1])-1]
diff --git a/newtmgr/cli/res_test.go b/newtmgr/cli/res_test.go
index 239bdb2..bde621b 100644
--- a/newtmgr/cli/res_test.go
+++ b/newtmgr/cli/res_test.go
@@ -50,6 +50,9 @@ func TestExtractResKv(t *testing.T) {
map[string]interface{}{"a": ""}},
{"only leading quote", []string{`a="x`},
map[string]interface{}{"a": `"x`}},
+ // A lone quote is not a quoted string; it used to panic.
+ {"single quote", []string{`a="`},
+ map[string]interface{}{"a": `"`}},
{"bool true", []string{"a=true"}, map[string]interface{}{"a": true}},
{"bool mixed case", []string{"a=FaLsE"},
map[string]interface{}{"a": false}},