From cf74b4df5decfc3e4d31f0953bb261c630961e50 Mon Sep 17 00:00:00 2001 From: Artem Poltorzhitskiy Date: Tue, 23 Apr 2024 19:46:06 +0200 Subject: [PATCH] Fix: diff OR primitive (#1015) * Fix: diff OR primitive * Fix: security issue --- go.mod | 12 ++++++------ go.sum | 24 ++++++++++++------------ internal/bcd/ast/ast_test.go | 4 ++-- internal/bcd/ast/miguel.go | 3 +++ internal/bcd/ast/or.go | 4 ++-- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 1d2bc8b6f..fd308aa5a 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/go-playground/validator/v10 v10.15.5 github.com/go-testfixtures/testfixtures/v3 v3.9.0 github.com/google/uuid v1.3.0 - github.com/grafana/pyroscope-go v1.0.3 + github.com/grafana/pyroscope-go v1.1.1 github.com/iancoleman/strcase v0.3.0 github.com/ipfs/go-cid v0.3.2 github.com/jessevdk/go-flags v1.5.0 @@ -38,7 +38,7 @@ require ( github.com/uptrace/bun/driver/pgdriver v1.1.16 github.com/yhirose/go-peg v0.0.0-20210804202551-de25d6753cf1 go.uber.org/mock v0.2.0 - golang.org/x/crypto v0.17.0 + golang.org/x/crypto v0.21.0 golang.org/x/time v0.3.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -79,7 +79,7 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect github.com/gorilla/css v1.0.0 // indirect - github.com/grafana/pyroscope-go/godeltaprof v0.1.4 // indirect + github.com/grafana/pyroscope-go/godeltaprof v0.1.6 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.5.4 // indirect @@ -87,7 +87,7 @@ require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/karlseguin/expect v1.0.8 // indirect - github.com/klauspost/compress v1.16.5 // indirect + github.com/klauspost/compress v1.17.3 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -136,9 +136,9 @@ require ( golang.org/x/arch v0.5.0 // indirect golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect golang.org/x/mod v0.11.0 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/net v0.23.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.10.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect diff --git a/go.sum b/go.sum index d4dafac1e..ad7c35ffd 100644 --- a/go.sum +++ b/go.sum @@ -176,10 +176,10 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= -github.com/grafana/pyroscope-go v1.0.3 h1:8WWmItzLfg4m8G+j//ElSjMeMr88Y6Lvblar6qeTyKk= -github.com/grafana/pyroscope-go v1.0.3/go.mod h1:0d7ftwSMBV/Awm7CCiYmHQEG8Y44Ma3YSjt+nWcWztY= -github.com/grafana/pyroscope-go/godeltaprof v0.1.4 h1:mDsJ3ngul7UfrHibGQpV66PbZ3q1T8glz/tK3bQKKEk= -github.com/grafana/pyroscope-go/godeltaprof v0.1.4/go.mod h1:1HSPtjU8vLG0jE9JrTdzjgFqdJ/VgN7fvxBNq3luJko= +github.com/grafana/pyroscope-go v1.1.1 h1:PQoUU9oWtO3ve/fgIiklYuGilvsm8qaGhlY4Vw6MAcQ= +github.com/grafana/pyroscope-go v1.1.1/go.mod h1:Mw26jU7jsL/KStNSGGuuVYdUq7Qghem5P8aXYXSXG88= +github.com/grafana/pyroscope-go/godeltaprof v0.1.6 h1:nEdZ8louGAplSvIJi1HVp7kWvFvdiiYg3COLlTwJiFo= +github.com/grafana/pyroscope-go/godeltaprof v0.1.6/go.mod h1:Tk376Nbldo4Cha9RgiU7ik8WKFkNpfds98aUzS8omLE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= @@ -226,8 +226,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= -github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA= +github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= @@ -434,8 +434,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4= golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= @@ -459,8 +459,8 @@ golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -495,8 +495,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/internal/bcd/ast/ast_test.go b/internal/bcd/ast/ast_test.go index b70fe1116..956cc1808 100644 --- a/internal/bcd/ast/ast_test.go +++ b/internal/bcd/ast/ast_test.go @@ -1106,7 +1106,7 @@ func TestTypedAst_Diff(t *testing.T) { tree: `{"prim":"or","args":[{"prim":"int"},{"prim":"string"}]}`, curr: `{"prim":"Left","args":[{"int":"10"}]}`, prev: `{"prim":"Right","args":[{"string":"test"}]}`, - want: `{"prim":"or","type":"or","name":"@or_1","diff_type":"update","children":[{"prim":"string","type":"string","name":"@string_3","diff_type":"update","value":"test"}]}`, + want: `{"prim":"or","type":"or","name":"@or_1","diff_type":"update","children":[{"prim":"int","type":"int","name":"@int_2","diff_type":"update","value":"10"}]}`, }, { name: "or test", tree: `{"prim":"or","args":[{"prim":"int"},{"prim":"string"}]}`, @@ -1118,7 +1118,7 @@ func TestTypedAst_Diff(t *testing.T) { tree: `{"prim":"or","args":[{"prim":"int"},{"prim":"string"}]}`, curr: `{"prim":"Right","args":[{"string":"test"}]}`, prev: `{"prim":"Left","args":[{"int":"0"}]}`, - want: `{"prim":"or","type":"or","name":"@or_1","diff_type":"update","children":[{"prim":"int","type":"int","name":"@int_2","diff_type":"update","value":"0"}]}`, + want: `{"prim":"or","type":"or","name":"@or_1","diff_type":"update","children":[{"prim":"string","type":"string","name":"@string_3","diff_type":"update","value":"test"}]}`, }, { name: "or test", tree: `{"prim":"or","args":[{"prim":"int"},{"prim":"string"}]}`, diff --git a/internal/bcd/ast/miguel.go b/internal/bcd/ast/miguel.go index 1a13d903c..0cb1a7ccc 100644 --- a/internal/bcd/ast/miguel.go +++ b/internal/bcd/ast/miguel.go @@ -42,6 +42,9 @@ func (node *MiguelNode) print(depth int) string { if node.Value != nil { s.WriteString(fmt.Sprintf(" value=%v", node.Value)) } + if node.DiffType != "" { + s.WriteString(fmt.Sprintf(" diff_type=%v", node.DiffType)) + } s.WriteByte('\n') for i := range node.Children { s.WriteString(node.Children[i].print(depth + 1)) diff --git a/internal/bcd/ast/or.go b/internal/bcd/ast/or.go index 5a9c0604a..d83317edf 100644 --- a/internal/bcd/ast/or.go +++ b/internal/bcd/ast/or.go @@ -427,7 +427,7 @@ func (or *Or) Distinguish(x Distinguishable) (*MiguelNode, error) { case or.key == 0 && second.key == 0: default: if second.key == rightKey { - child, err := second.RightType.ToMiguel() + child, err := or.LeftType.ToMiguel() if err != nil { return nil, err } @@ -435,7 +435,7 @@ func (or *Or) Distinguish(x Distinguishable) (*MiguelNode, error) { node.setDiffType(MiguelKindUpdate) } if second.key == leftKey { - child, err := second.LeftType.ToMiguel() + child, err := or.RightType.ToMiguel() if err != nil { return nil, err }