mirror of
https://github.com/alibaba/higress.git
synced 2026-03-10 19:51:00 +08:00
Fix int convertion cve (#25)
This commit is contained in:
@@ -95,7 +95,7 @@ func (f fallback) Parse(annotations Annotations, config *Ingress, globalContext
|
||||
codesStr := splitBySeparator(codes, ",")
|
||||
var codesUint32 []uint32
|
||||
for _, rawCode := range codesStr {
|
||||
code, err := strconv.Atoi(rawCode)
|
||||
code, err := strconv.ParseUint(rawCode, 10, 32)
|
||||
if err != nil {
|
||||
IngressLog.Errorf("Custom HTTP code %s within ingress %s/%s is invalid", rawCode, config.Namespace, config.Name)
|
||||
continue
|
||||
|
||||
@@ -61,21 +61,21 @@ func (l localRateLimit) Parse(annotations Annotations, config *Ingress, _ *Globa
|
||||
config.localRateLimit = local
|
||||
}()
|
||||
|
||||
multiplier := defaultBurstMultiplier
|
||||
if m, err := annotations.ParseIntForMSE(limitBurstMultiplier); err == nil {
|
||||
var multiplier uint32 = defaultBurstMultiplier
|
||||
if m, err := annotations.ParseUint32ForMSE(limitBurstMultiplier); err == nil {
|
||||
multiplier = m
|
||||
}
|
||||
|
||||
if rpm, err := annotations.ParseIntForMSE(limitRPM); err == nil {
|
||||
if rpm, err := annotations.ParseUint32ForMSE(limitRPM); err == nil {
|
||||
local = &localRateLimitConfig{
|
||||
MaxTokens: uint32(rpm * multiplier),
|
||||
TokensPerFill: uint32(rpm),
|
||||
MaxTokens: rpm * multiplier,
|
||||
TokensPerFill: rpm,
|
||||
FillInterval: minute,
|
||||
}
|
||||
} else if rps, err := annotations.ParseIntForMSE(limitRPS); err == nil {
|
||||
} else if rps, err := annotations.ParseUint32ForMSE(limitRPS); err == nil {
|
||||
local = &localRateLimitConfig{
|
||||
MaxTokens: uint32(rps * multiplier),
|
||||
TokensPerFill: uint32(rps),
|
||||
MaxTokens: rps * multiplier,
|
||||
TokensPerFill: rps,
|
||||
FillInterval: second,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -60,8 +60,8 @@ func (r retry) Parse(annotations Annotations, config *Ingress, _ *GlobalContext)
|
||||
config.Retry = retryConfig
|
||||
}()
|
||||
|
||||
if count, err := annotations.ParseIntASAP(retryCount); err == nil {
|
||||
retryConfig.retryCount = int32(count)
|
||||
if count, err := annotations.ParseInt32ASAP(retryCount); err == nil {
|
||||
retryConfig.retryCount = count
|
||||
}
|
||||
|
||||
if timeout, err := annotations.ParseIntASAP(perRetryTimeout); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user