Skip to content

Commit 2152696

Browse files
committed
Bug fix for out of bounds slice access
1 parent a2d93a0 commit 2152696

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

server/functions/json.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ var json_in = framework.Function1{
4747
if json.Valid(unsafe.Slice(unsafe.StringData(input), len(input))) {
4848
return input, nil
4949
}
50-
return nil, pgtypes.ErrInvalidSyntaxForType.New("json", input[:10]+"...")
50+
if len(input) > 10 {
51+
input = input[:10] + "..."
52+
}
53+
return nil, pgtypes.ErrInvalidSyntaxForType.New("json", input)
5154
},
5255
}
5356

testing/go/types_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,14 @@ var typesTests = []ScriptTest{
12181218
{`"\ud83d\ude04\ud83d\udc36"`},
12191219
},
12201220
},
1221+
{
1222+
Query: `SELECT '{'::json`,
1223+
ExpectedErr: "invalid input syntax for type json",
1224+
},
1225+
{
1226+
Query: `SELECT '{"key": "value"'::json`,
1227+
ExpectedErr: "invalid input syntax for type json",
1228+
},
12211229
},
12221230
},
12231231
{

0 commit comments

Comments
 (0)