From: Andreas Stieger Date: Thu, 06 Oct 2016 13:26:04 +0000 References: bsc#845530 bsc#1003324 This patch ensures correct path expansion for the local time zone link. The 2016g release re-worked much of the code, however the problem with broken symlinks remain. Brought up on mailing list: http://mm.icann.org/pipermail/tz/2016-October/024280.html Index: timezone-2016g/zic.c =================================================================== --- timezone-2016g.orig/zic.c 2016-09-06 04:39:50.000000000 +0000 +++ timezone-2016g/zic.c 2016-10-06 13:18:13.752297564 +0000 @@ -764,12 +764,32 @@ namecheck(const char *name) return componentcheck(name, component, cp); } +static char * +relname(char const *dir, char const *base) +{ + if (*base == '/') + return ecpyalloc(base); + else { + size_t dir_len = strlen(dir); + bool needs_slash = dir_len && dir[dir_len - 1] != '/'; + char *result = emalloc(dir_len + needs_slash + strlen(base) + 1); + result[dir_len] = '/'; + strcpy(result + dir_len + needs_slash, base); + return memcpy(result, dir, dir_len); + } +} + static void dolink(char const *fromfield, char const *tofield, bool staysymlink) { register int fromisdir; bool todirs_made = false; int link_errno; + register char * fromname; + register char * toname; + + fromname = relname(directory, fromfield); + toname = relname(directory, tofield); /* ** We get to be careful here since @@ -800,7 +820,7 @@ dolink(char const *fromfield, char const link_errno = link(fromfield, tofield) == 0 ? 0 : errno; } if (link_errno != 0) { - const char *s = fromfield; + const char *s = fromname; const char *t; char *p; size_t dotdots = 0; @@ -810,9 +830,9 @@ dolink(char const *fromfield, char const do t = s; while ((s = strchr(s, '/')) - && strncmp(fromfield, tofield, ++s - fromfield) == 0); + && strncmp(fromname, tofield, ++s - fromname) == 0); - for (s = tofield + (t - fromfield); *s; s++) + for (s = tofield + (t - fromname); *s; s++) dotdots += *s == '/'; symlinkcontents = emalloc(3 * dotdots + strlen(t) + 1); for (p = symlinkcontents; dotdots-- != 0; p += 3)