diff -r f746f601c35c -r 62cc92445234 dav/sync.c --- a/dav/sync.c Tue Apr 16 11:46:53 2019 +0200 +++ b/dav/sync.c Sat Apr 20 12:31:08 2019 +0200 @@ -2421,7 +2421,8 @@ } if(S_ISLNK(s.st_mode)) { - size_t lnksize = s.st_size > 256 ? s.st_size : 256; + off_t l_sz = s.st_size + 16; + size_t lnksize = l_sz > 256 ? l_sz : 256; char *lnkbuf = malloc(lnksize); ssize_t len = 0; @@ -2437,10 +2438,28 @@ } if(len > 0) { - res->link_target = lnkbuf; - res->link_target[len] = 0; - } else { - free(lnkbuf); + // readlink successful + lnkbuf[len] = 0; + + char *normalized = NULL; + if(lnkbuf[0] != '/') { + char *link_parent = util_parent_path(res->path); + char *abs_link_parent = util_concat_path(dir->path, link_parent); + char *link = util_concat_path(abs_link_parent, lnkbuf); + normalized = util_path_normalize(link); + free(abs_link_parent); + free(link_parent); + free(link); + } else { + normalized = util_path_normalize(lnkbuf); + } + + if(util_path_isrelated(dir->path, normalized)) { + // the link points to a file inside the syncdir + char *rel = util_create_relative_path(normalized, file_path); + res->link_target = rel; + } + free(normalized); } free(lnkbuf);