Skip to content

Commit

Permalink
Fortify Svc::flex_{target,min,max} evaluation against non int castabl…
Browse files Browse the repository at this point in the history
…e value

Apply the default when that happens.

Better than adding sanity checks in all codepaths relying on an int value
there.
  • Loading branch information
cvaroqui committed Nov 27, 2020
1 parent c806ff8 commit f6f56cf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions opensvc/core/objects/svc.py
Expand Up @@ -3043,7 +3043,11 @@ def soft_anti_affinity(self):

@lazy
def flex_min(self):
val = self.oget("DEFAULT", "flex_min")
try:
val = self.oget("DEFAULT", "flex_min")
int(val)
except (ValueError, TypeError, ex.OptNotFound):
val = 0
if val < 0:
val = 0
nb_nodes = len(self.nodes | self.drpnodes)
Expand All @@ -3056,7 +3060,8 @@ def flex_max(self):
nb_nodes = len(self.peers)
try:
val = self.conf_get("DEFAULT", "flex_max")
except ex.OptNotFound:
int(val)
except (ValueError, TypeError, ex.OptNotFound):
return nb_nodes
if val > nb_nodes:
val = nb_nodes
Expand All @@ -3067,8 +3072,9 @@ def flex_max(self):
@lazy
def flex_target(self):
try:
return self.conf_get("DEFAULT", "flex_target")
except ex.OptNotFound:
val = self.conf_get("DEFAULT", "flex_target")
return int(val)
except (ValueError, TypeError, ex.OptNotFound):
return self.flex_min

@lazy
Expand Down

0 comments on commit f6f56cf

Please sign in to comment.