From ca5327b9085f3c49972e034e70e70bfd88f82e05 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 9 Mar 2020 09:30:16 -0400 Subject: [PATCH] Make strtobool even more robust If strtobool fails, return False always. --- api-daemon/pvcapid/flaskapi.py | 5 ++++- api-daemon/pvcapid/helper.py | 5 ++++- api-daemon/pvcapid/provisioner.py | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/api-daemon/pvcapid/flaskapi.py b/api-daemon/pvcapid/flaskapi.py index b2672801..0a9eaff8 100755 --- a/api-daemon/pvcapid/flaskapi.py +++ b/api-daemon/pvcapid/flaskapi.py @@ -50,7 +50,10 @@ def strtobool(stringv): return False if isinstance(stringv, bool): return bool(stringv) - return bool(dustrtobool(stringv)) + try: + return bool(dustrtobool(stringv)) + except: + return False # Parse the configuration file try: diff --git a/api-daemon/pvcapid/helper.py b/api-daemon/pvcapid/helper.py index e3b25cde..58fe200a 100755 --- a/api-daemon/pvcapid/helper.py +++ b/api-daemon/pvcapid/helper.py @@ -38,7 +38,10 @@ def strtobool(stringv): return False if isinstance(stringv, bool): return bool(stringv) - return bool(dustrtobool(stringv)) + try: + return bool(dustrtobool(stringv)) + except: + return False # # Initialization function diff --git a/api-daemon/pvcapid/provisioner.py b/api-daemon/pvcapid/provisioner.py index fd81e4d3..337dedbf 100755 --- a/api-daemon/pvcapid/provisioner.py +++ b/api-daemon/pvcapid/provisioner.py @@ -47,7 +47,10 @@ def strtobool(stringv): return False if isinstance(stringv, bool): return bool(stringv) - return bool(dustrtobool(stringv)) + try: + return bool(dustrtobool(stringv)) + except: + return False # # Exceptions (used by Celery tasks)