Repository: incubator-mynewt-newt Updated Branches: refs/heads/1_0_0_b1_dev 00ec2a349 -> b46449cee
MYNEWT-483 - Don't allow numeric syscfg names. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/f7a5983c Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f7a5983c Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f7a5983c Branch: refs/heads/1_0_0_b1_dev Commit: f7a5983c146253527961244f49a21e2485d5e12a Parents: 00ec2a3 Author: Christopher Collins <[email protected]> Authored: Fri Nov 11 15:42:49 2016 -0800 Committer: Christopher Collins <[email protected]> Committed: Fri Nov 11 15:42:49 2016 -0800 ---------------------------------------------------------------------- newt/cli/target_cmds.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f7a5983c/newt/cli/target_cmds.go ---------------------------------------------------------------------- diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go index bb82f32..b931607 100644 --- a/newt/cli/target_cmds.go +++ b/newt/cli/target_cmds.go @@ -141,11 +141,11 @@ func targetShowCmd(cmd *cobra.Command, args []string) { } } -func targetSyscfgKVFromStr(str string) map[string]string { +func targetSyscfgKVFromStr(str string) (map[string]string, error) { vals := map[string]string{} if strings.TrimSpace(str) == "" { - return vals + return vals, nil } // Separate syscfg vals are delimited by ':'. @@ -154,6 +154,11 @@ func targetSyscfgKVFromStr(str string) map[string]string { // Key-value pairs are delimited by '='. If no '=' is present, assume the // string is the key name and the value is 1. for _, f := range fields { + if _, err := util.AtoiNoOct(f); err == nil { + return nil, util.FmtNewtError( + "Invalid setting name \"%s\"; must not be a number", f) + } + kv := strings.SplitN(f, "=", 2) switch len(kv) { case 1: @@ -163,7 +168,7 @@ func targetSyscfgKVFromStr(str string) map[string]string { } } - return vals + return vals, nil } func targetSyscfgKVToStr(syscfgKv map[string]string) string { @@ -228,7 +233,11 @@ func targetSetCmd(cmd *cobra.Command, args []string) { // instead of the target. if kv[0] == "target.syscfg" { t.Package().SyscfgV = viper.New() - kv := targetSyscfgKVFromStr(kv[1]) + kv, err := targetSyscfgKVFromStr(kv[1]) + if err != nil { + NewtUsage(cmd, err) + } + t.Package().SyscfgV.Set("syscfg.vals", kv) } else if kv[0] == "target.cflags" || kv[0] == "target.lflags" ||
