From d480decd0523c7fe4cb07b26dfc86d33e609df1e Mon Sep 17 00:00:00 2001 From: Michal Gorecki Date: Mon, 9 Sep 2024 09:56:43 +0200 Subject: [PATCH] newt: Fix config check crashes We should use DeepEqual to compare interface values. In some cases Value interface might contain a map with some more keys than just "value" key - for example "description" key. This will cause DeepEqual to fail, even if the "value" keys would be the same. However before returning an error we also check if Expr field of both entries is not nil. We can assume that in that case no additional keys in map will be present and no false positive error will be returned. --- newt/ycfg/ycfg.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/newt/ycfg/ycfg.go b/newt/ycfg/ycfg.go index 08d334771..50a7c1478 100644 --- a/newt/ycfg/ycfg.go +++ b/newt/ycfg/ycfg.go @@ -22,6 +22,7 @@ package ycfg import ( "fmt" "mynewt.apache.org/newt/newt/cfgv" + "reflect" "strings" "github.com/spf13/cast" @@ -470,8 +471,8 @@ func (yc *YCfg) GetStringMap( } if _, exists := result[k]; exists { - if (entry.Value != result[k].Value) && (result[k].Expr != nil) { - return nil, fmt.Errorf("Setting %s collision - two conditions true:\n[%s, %s]\n"+ + if !reflect.DeepEqual(entry.Value, result[k].Value) && (result[k].Expr != nil) && (entry.Expr != nil) { + return nil, fmt.Errorf("setting %s collision - two conditions true:\n[%s, %s]\n"+ "Conflicting file: %s", k, entry.Expr.String(), result[k].Expr.String(), yc.name) }