Fix int convertion cve (#25)

This commit is contained in:
Yang
2022-11-04 15:31:34 +08:00
committed by GitHub
parent a525fcb1b5
commit 31b78bf40c
4 changed files with 66 additions and 11 deletions

View File

@@ -166,6 +166,54 @@ func (a Annotations) ParseIntForMSE(key string) (int, error) {
return 0, ErrMissingAnnotations
}
func (a Annotations) ParseInt32(key string) (int32, error) {
if len(a) == 0 {
return 0, ErrMissingAnnotations
}
val, ok := a[buildNginxAnnotationKey(key)]
if ok {
i, err := strconv.ParseInt(val, 10, 32)
if err != nil {
return 0, ErrInvalidAnnotationValue
}
return int32(i), nil
}
return 0, ErrMissingAnnotations
}
func (a Annotations) ParseInt32ForMSE(key string) (int32, error) {
if len(a) == 0 {
return 0, ErrMissingAnnotations
}
val, ok := a[buildMSEAnnotationKey(key)]
if ok {
i, err := strconv.ParseInt(val, 10, 32)
if err != nil {
return 0, ErrInvalidAnnotationValue
}
return int32(i), nil
}
return 0, ErrMissingAnnotations
}
func (a Annotations) ParseUint32ForMSE(key string) (uint32, error) {
if len(a) == 0 {
return 0, ErrMissingAnnotations
}
val, ok := a[buildMSEAnnotationKey(key)]
if ok {
i, err := strconv.ParseUint(val, 10, 32)
if err != nil {
return 0, ErrInvalidAnnotationValue
}
return uint32(i), nil
}
return 0, ErrMissingAnnotations
}
func (a Annotations) ParseIntASAP(key string) (int, error) {
if result, err := a.ParseInt(key); err == nil {
return result, nil
@@ -173,6 +221,13 @@ func (a Annotations) ParseIntASAP(key string) (int, error) {
return a.ParseIntForMSE(key)
}
func (a Annotations) ParseInt32ASAP(key string) (int32, error) {
if result, err := a.ParseInt32(key); err == nil {
return result, nil
}
return a.ParseInt32ForMSE(key)
}
func (a Annotations) Has(key string) bool {
if len(a) == 0 {
return false