Skip to content

Commit

Permalink
fix(dracut-install): do not assume handled path starts with sysrootdir
Browse files Browse the repository at this point in the history
When using --sysrootdir argument, we cannot assume fulldstpath and
fullsrcpath always start with sysrootdir. When dracut_install is
called on destination directory, this results in passing pointer which
is often beyond valid buffer.

Signed-off-by: Ondrej Kubik <ondrej.kubik@canonical.com>
  • Loading branch information
kubiko authored and LaszloGombos committed Sep 7, 2024
1 parent 91b1574 commit 7bc1f53
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/install/dracut-install.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,10 @@ static int dracut_install(const char *orig_src, const char *orig_dst, bool isdir
if (ret == 0) {
if (resolvedeps && S_ISREG(sb.st_mode) && (sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
log_debug("'%s' already exists, but checking for any deps", fulldstpath);
ret = resolve_deps(fullsrcpath + sysrootdirlen);
if (sysrootdirlen && (strncmp(fulldstpath, sysrootdir, sysrootdirlen) == 0))
ret = resolve_deps(fulldstpath + sysrootdirlen);
else
ret = resolve_deps(fullsrcpath);
} else
log_debug("'%s' already exists", fulldstpath);

Expand Down Expand Up @@ -982,8 +985,13 @@ static int dracut_install(const char *orig_src, const char *orig_dst, bool isdir
}

if (src_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
if (resolvedeps)
ret += resolve_deps(fullsrcpath + sysrootdirlen);
if (resolvedeps) {
/* ensure fullsrcpath contains sysrootdir */
if (sysrootdirlen && (strncmp(fullsrcpath, sysrootdir, sysrootdirlen) == 0))
ret += resolve_deps(fullsrcpath + sysrootdirlen);
else
ret += resolve_deps(fullsrcpath);
}
if (arg_hmac) {
/* copy .hmac files also */
hmac_install(src, dst, NULL);
Expand Down

0 comments on commit 7bc1f53

Please sign in to comment.