Skip to content

Commit

Permalink
newt: Fix config check crashes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m-gorecki committed Sep 9, 2024
1 parent c7afc5f commit d480dec
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions newt/ycfg/ycfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package ycfg
import (
"fmt"
"mynewt.apache.org/newt/newt/cfgv"
"reflect"
"strings"

"github.com/spf13/cast"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d480dec

Please sign in to comment.