Skip to content

Commit 873f6f8

Browse files
authored
[oneimage] Check if graph service address got from dhcp is valid url (#324)
* [oneimage] Check if graph service address got from dhcp is valid url
1 parent 151a7d2 commit 873f6f8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

files/image_config/updategraph/updategraph

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ if [ "$src" = "dhcp" ]; then
2929

3030
HOSTNAME=`hostname -s`
3131
GRAPH_URL=`sonic-cfggen -t /tmp/dhcp_graph_url -a "{\"hostname\": \"$HOSTNAME\"}"`
32+
URL_REGEX='^(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'
33+
if [[ ! $GRAPH_URL =~ $URL_REGEX ]]; then
34+
echo "\"$GRAPH_URL\" is not a valid url. Skipping graph update."
35+
exit 0
36+
fi
3237
if [ "$dhcp_as_static" = "true" ]; then
33-
sed -i "/src=d/d" /etc/sonic/updategraph.conf
34-
echo "src=$GRAPH_URL" >> /etc/sonic/updategraph.conf
38+
sed -i "/src=/d" /etc/sonic/updategraph.conf
39+
echo "src=\"$GRAPH_URL\"" >> /etc/sonic/updategraph.conf
3540
fi
3641
else
3742
GRAPH_URL=$src

0 commit comments

Comments
 (0)