From 71d76697a667cc3fb3f748851544d951f7ecfdf0 Mon Sep 17 00:00:00 2001 From: Dimitar Tsankov Date: Wed, 14 Dec 2022 13:58:12 +0200 Subject: [PATCH] Added validation for IPv4/v6 address. --- google_cloud_dns/rootfs/etc/services.d/google_cloud_dns/run | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google_cloud_dns/rootfs/etc/services.d/google_cloud_dns/run b/google_cloud_dns/rootfs/etc/services.d/google_cloud_dns/run index c867dd1..742e8f2 100755 --- a/google_cloud_dns/rootfs/etc/services.d/google_cloud_dns/run +++ b/google_cloud_dns/rootfs/etc/services.d/google_cloud_dns/run @@ -133,7 +133,7 @@ do [[ ${CONFIG_IPV4} != *:/* ]] && IPV4=${CONFIG_IPV4} || IPV4=$(curl -s -m 10 "${CONFIG_IPV4}") || true [[ ${CONFIG_IPV6} != *:/* ]] && IPV6=${CONFIG_IPV6} || IPV6=$(curl -s -m 10 "${CONFIG_IPV6}") || true - if [ "${IPV4}" != '' ] && [ "${IPV4}" != "${LAST_IPV4}" ] + if [[ "${IPV4}" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] && [ "${IPV4}" != "${LAST_IPV4}" ] then EXIT_CODE=0 google_cloud_update_dns.sh set "${FQDN}" A "${IPV4}" || EXIT_CODE=${?} @@ -147,7 +147,7 @@ do fi fi - if [ "${IPV6}" != '' ] && [ "${IPV6}" != "${LAST_IPV6}" ] + if [[ "${IPV6}" =~ ^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$ ]] && [ "${IPV6}" != "${LAST_IPV6}" ] then EXIT_CODE=0 google_cloud_update_dns.sh set "${FQDN}" AAAA "${IPV6}" || EXIT_CODE=${?}