diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index 203905b85c7c..68fbe6eb9c19 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -29,9 +29,14 @@ if [ "$src" = "dhcp" ]; then HOSTNAME=`hostname -s` GRAPH_URL=`sonic-cfggen -t /tmp/dhcp_graph_url -a "{\"hostname\": \"$HOSTNAME\"}"` + URL_REGEX='^(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$' + if [[ ! $GRAPH_URL =~ $URL_REGEX ]]; then + echo "\"$GRAPH_URL\" is not a valid url. Skipping graph update." + exit 0 + fi if [ "$dhcp_as_static" = "true" ]; then - sed -i "/src=d/d" /etc/sonic/updategraph.conf - echo "src=$GRAPH_URL" >> /etc/sonic/updategraph.conf + sed -i "/src=/d" /etc/sonic/updategraph.conf + echo "src=\"$GRAPH_URL\"" >> /etc/sonic/updategraph.conf fi else GRAPH_URL=$src