Skip to content

setup-timezone: Fix multi/unexpected '/' cause multi-slash symlink

Minoplhy requested to merge minoplhy/alpine-conf:master into master

User enters timezone directory with '/' like Europe/ cause a double slash on /etc/localtime symlink, which might break some software like Postgresql(first hand experience).

like this: /etc/localtime -> /etc/zoneinfo/Europe//Malta

or in worst case: /etc/localtime -> /etc/zoneinfo/Europe/////////////////////////////////////////////////////////////Kiev

So I send user input on both timezone and sub-timezone to sed and

    1. replace multi-slash(//+) with single slash(/)
    1. replace single slash(/) on The end of user input to ""

Also, when the user does not input in the sub-timezone, unexpected '/' occurs due to the loop not skipping.

To reproduce:

before:

Which timezone are you in? [UTC] right/

What sub-timezone of 'right/' are you in? Etc///

What sub-timezone of 'right//Etc///' are you in? Universal

# ls -n /etc/localtime
/etc/localtime -> /etc/zoneinfo/right//Etc////Universal
Which timezone are you in? [UTC] Indian

What sub-timezone of 'Indian' are you in?

What sub-timezone of 'Indian/' are you in?

What sub-timezone of 'Indian//' are you in?

What sub-timezone of 'Indian///' are you in?

after:

Which timezone are you in? [UTC] right/

What sub-timezone of 'right' are you in? Etc///

What sub-timezone of 'right/Etc' are you in? Universal

# ls -n /etc/localtime
/etc/localtime -> /etc/zoneinfo/right/Etc/Universal
Which timezone are you in? [UTC] Indian

What sub-timezone of 'Indian' are you in?

What sub-timezone of 'Indian' are you in?

What sub-timezone of 'Indian' are you in?

What sub-timezone of 'Indian' are you in?
Edited by Minoplhy

Merge request reports

Loading