Skip to content

Commit 583cb71

Browse files
committed
fix(functions/switch_ubuntu_local_mirror): Fix missing validation of the region code
Signed-off-by: 林博仁(Buo-ren Lin) <[email protected]>
1 parent 7e35a82 commit 583cb71

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

functions.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,21 @@ switch_ubuntu_local_mirror(){
634634
'Warning: Unable to detect the local region code, falling back to the current settings.\n' \
635635
1>&2
636636
return 0
637-
else
637+
fi
638+
639+
local regex_region_code='^[a-z]{2,3}$'
640+
if ! [[ "${region_code}" =~ ${regex_region_code} ]]; then
638641
printf \
639-
'Info: Local region code determined to be "%s".\n' \
640-
"${region_code}"
642+
'Error: Local region code "%s" is not valid.\n' \
643+
"${region_code}" \
644+
1>&2
645+
return 2
641646
fi
642647

648+
printf \
649+
'Info: Local region code determined to be "%s".\n' \
650+
"${region_code}"
651+
643652
if test -n "${region_code}"; then
644653
printf \
645654
'Info: Checking whether the local Ubuntu archive mirror exists...\n'

0 commit comments

Comments
 (0)