summaryrefslogtreecommitdiff
path: root/lib/fprint.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2022-05-06 11:34:23 +0300
committerPanu Matilainen <pmatilai@redhat.com>2022-05-06 11:34:23 +0300
commit33da0fdff87786772ab8483c367bb0f07816fe14 (patch)
tree3b621676de2f2ac4dc3b4db10bb62e25681086cd /lib/fprint.c
parent328ff700a3260190bb4b980632a864e05845d0d2 (diff)
downloadrpm-33da0fdff87786772ab8483c367bb0f07816fe14.tar.gz
Clean up canonical dirname calculation
Handle path canonicalization and trailing slash centrally. No functional changes.
Diffstat (limited to 'lib/fprint.c')
-rw-r--r--lib/fprint.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/fprint.c b/lib/fprint.c
index b359697a3..eca0f14d7 100644
--- a/lib/fprint.c
+++ b/lib/fprint.c
@@ -132,15 +132,10 @@ static const struct fprintCacheEntry_s * cacheContainsDirectory(
static char * canonDir(rpmstrPool pool, rpmsid dirNameId)
{
const char * dirName = rpmstrPoolStr(pool, dirNameId);
- size_t cdnl = rpmstrPoolStrlen(pool, dirNameId);;
char *cdnbuf = NULL;
if (*dirName == '/') {
cdnbuf = xstrdup(dirName);
- cdnbuf = rpmCleanPath(cdnbuf);
- /* leave my trailing slashes along you b**** */
- if (cdnl > 1)
- cdnbuf = rstrcat(&cdnbuf, "/");
} else {
/* Using realpath on the arg isn't correct if the arg is a symlink,
* especially if the symlink is a dangling link. What we
@@ -149,12 +144,16 @@ static char * canonDir(rpmstrPool pool, rpmsid dirNameId)
*/
/* if the current directory doesn't exist, we might fail. oh well. */
- if ((cdnbuf = realpath(".", NULL)) != NULL) {
+ if ((cdnbuf = realpath(".", NULL)) != NULL)
cdnbuf = rstrscat(&cdnbuf, "/", dirName, NULL);
- (void)rpmCleanPath(cdnbuf); /* XXX possible /../ from concatenation */
- char *end = cdnbuf + strlen(cdnbuf);
- if (end[-1] != '/') *end++ = '/';
- *end = '\0';
+ }
+
+ /* ensure canonical path with a trailing slash */
+ if (cdnbuf) {
+ size_t cdnl = strlen(cdnbuf);
+ if (cdnl > 1) {
+ cdnbuf = rpmCleanPath(cdnbuf);
+ cdnbuf = rstrcat(&cdnbuf, "/");
}
}
return cdnbuf;