+ } else {
+ if ((p = strstr(fbuf, "/./")) != NULL) {
+ *p = '\0';
+ if (p == fbuf)
+ dir = "/";
+ else
+ dir = fbuf;
+ len -= p - fbuf + 3;
+ fn = p + 3;
+ } else
+ fn = fbuf;
+ /* Get rid of trailing "/" and "/.". */
+ while (len) {
+ if (fn[len - 1] == '/')
+ len--;
+ else if (len >= 2 && fn[len - 1] == '.'
+ && fn[len - 2] == '/') {
+ if (!(len -= 2) && !dir) {
+ len++;
+ break;
+ }
+ } else
+ break;
+ }
+ fn[len] = '\0';
+ /* Reject a ".." dir in the active part of the path. */
+ if ((p = strstr(fbuf, "..")) != NULL
+ && (p[2] == '/' || p[2] == '\0')
+ && (p == fbuf || p[-1] == '/')) {
+ rprintf(FERROR,
+ "using a \"..\" dir is invalid with --relative: %s\n",
+ fbuf);
+ exit_cleanup(RERR_SYNTAX);
+ }
+ }