Skip to content

Commit 310974d

Browse files
committed
fix(ttlv): panic if struct tag int values are out of bound
Fixes https://github.com/ovh/kmip-go/security/code-scanning/3 Signed-off-by: Pierre-Henri Symoneaux <pierre-henri.symoneaux@ovhcloud.com>
1 parent 699268c commit 310974d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ttlv/reflect.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@ func getFieldTag(fldT reflect.StructField, tagVal string) int {
7171
}
7272

7373
if strings.HasPrefix(tagVal, "0x") {
74-
n, err := strconv.ParseInt(tagVal[2:], 16, 64)
74+
n, err := strconv.ParseInt(tagVal[2:], 16, 0)
7575
if err != nil {
7676
panic(err)
7777
}
78+
if n <= 0 {
79+
panic("the tag must be strictly positive")
80+
}
81+
if n > 0xFFFFFF {
82+
panic("the tag cannot be bigger than 3 bytes")
83+
}
7884
return int(n)
7985
}
8086

0 commit comments

Comments
 (0)