Skip to content

Commit

Permalink
perf(dracut-install): convert_abs_rel: don't allocate target parent r…
Browse files Browse the repository at this point in the history
…ealpath
  • Loading branch information
nabijaczleweli committed Jun 24, 2022
1 parent 5e68016 commit 68778f1
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/install/dracut-install.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static char *convert_abs_rel(const char *from, const char *target)
/* we use the 4*MAXPATHLEN, which should not overrun */
char buf[MAXPATHLEN * 4];
_cleanup_free_ char *realtarget = NULL, *realfrom = NULL, *from_dir_p = NULL;
_cleanup_free_ char *target_dir_p = NULL, *realpath_p = NULL;
_cleanup_free_ char *target_dir_p = NULL;
size_t level = 0, fromlevel = 0, targetlevel = 0;
int l;
size_t i, rl, dirlen;
Expand All @@ -187,16 +187,14 @@ static char *convert_abs_rel(const char *from, const char *target)
target_dir_p = strndup(target, dirlen);
if (!target_dir_p)
return strdup(from + strlen(destrootdir));

realpath_p = realpath(target_dir_p, NULL);
if (realpath_p == NULL) {
if (realpath(target_dir_p, buf) == NULL) {
log_warning("convert_abs_rel(): target '%s' directory has no realpath: %m", target);
return strdup(from + strlen(destrootdir));
}

for (i = dirlen + 1; target[i] == '/'; ++i)
;
_asprintf(&realtarget, "%s/%s", realpath_p, &target[i]);
_asprintf(&realtarget, "%s/%s", buf, target + i);

/* now calculate the relative path from <from> to <target> and
store it in <buf>
Expand Down

0 comments on commit 68778f1

Please sign in to comment.