From c218072ac1ae5bcbf52a28bdfec3d325efe352f5 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Wed, 17 Oct 2018 18:15:22 +0200 Subject: [PATCH] filters.py: Catch ValueError in case of malformatted IP address Signed-off-by: Adrian Schmutzler --- ffmap/web/filters.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ffmap/web/filters.py b/ffmap/web/filters.py index 9edbf4b..6e567c6 100644 --- a/ffmap/web/filters.py +++ b/ffmap/web/filters.py @@ -72,11 +72,17 @@ def bin2ipv6filter(d): @filters.app_template_filter('ip2int') def ip2intfilter(d): - return int(ip_address(d)) + try: + return int(ip_address(d)) + except ValueError as e: + return 0 @filters.app_template_filter('ipnet2int') def ipnet2intfilter(d): - return int(ip_address(d.split("/")[0])) + try: + return int(ip_address(d.split("/")[0])) + except ValueError as e: + return 0 @filters.app_template_filter('utc2local') def utc2local(dt):