unpack: correctly take into account rootdir while checking symlinks.

This commit is contained in:
Juan RP 2012-10-27 10:36:39 +02:00
parent 978013bfbf
commit 03567ecb70

View File

@ -196,7 +196,7 @@ unpack_archive(struct xbps_handle *xhp,
size_t i, entry_idx = 0; size_t i, entry_idx = 0;
const char *file, *entry_pname, *transact, *pkgname; const char *file, *entry_pname, *transact, *pkgname;
const char *version, *pkgver, *fname, *tgtlnk; const char *version, *pkgver, *fname, *tgtlnk;
char *dname, *buf, *buf2, *p, *p2, *p3, *pkgfilesd, *pkgpropsd; char *dname, *buf, *buf2, *p, *p2, *pkgfilesd, *pkgpropsd;
int ar_rv, rv, rv_stat, flags; int ar_rv, rv, rv_stat, flags;
bool preserve, update, conf_file, file_exists, skip_obsoletes; bool preserve, update, conf_file, file_exists, skip_obsoletes;
bool softreplace, skip_extract; bool softreplace, skip_extract;
@ -456,30 +456,26 @@ unpack_archive(struct xbps_handle *xhp,
if (file_exists) { if (file_exists) {
buf = realpath(entry_pname, NULL); buf = realpath(entry_pname, NULL);
assert(buf); assert(buf);
if (strcmp(xhp->rootdir, "/")) if (strcmp(xhp->rootdir, "/")) {
p = strlen(xhp->rootdir) + buf; p = buf;
else p += strlen(xhp->rootdir);
} else
p = buf; p = buf;
assert(p); assert(p);
tgtlnk = find_pkg_symlink_target(filesd, tgtlnk = find_pkg_symlink_target(filesd,
entry_pname); entry_pname);
assert(tgtlnk); assert(tgtlnk);
if (strncmp(tgtlnk, "./", 2) == 0) { if (strncmp(tgtlnk, "./", 2) == 0) {
p3 = strdup(entry_pname); buf2 = strdup(entry_pname);
assert(p3);
dname = dirname(p3);
buf2 = xbps_xasprintf("%s/%s", dname, tgtlnk);
assert(buf2); assert(buf2);
free(p3); dname = dirname(buf2);
p2 = xbps_xasprintf("%s/%s", dname, tgtlnk);
assert(p2);
free(buf2);
} else { } else {
buf2 = strdup(tgtlnk); p2 = strdup(tgtlnk);
assert(buf2); assert(p2);
} }
if (strcmp(xhp->rootdir, "/"))
p2 = strlen(xhp->rootdir) + buf2;
else
p2 = buf2;
xbps_dbg_printf(xhp, "%s: symlink %s cur: %s " xbps_dbg_printf(xhp, "%s: symlink %s cur: %s "
"new: %s\n", pkgver, entry_pname, p, p2); "new: %s\n", pkgver, entry_pname, p, p2);
@ -490,7 +486,6 @@ unpack_archive(struct xbps_handle *xhp,
skip_extract = true; skip_extract = true;
} }
free(buf); free(buf);
free(buf2);
} }
} }
/* /*