Skip to content

Commit

Permalink
perf(dracut-install): don't reallocate {src,dst}path in hmac_install()
Browse files Browse the repository at this point in the history
  • Loading branch information
nabijaczleweli authored and aafeijoo-suse committed Dec 28, 2022
1 parent a20556f commit 77226cb
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/install/dracut-install.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,9 @@ static int resolve_deps(const char *src)
/* Install ".<filename>.hmac" file for FIPS self-checks */
static int hmac_install(const char *src, const char *dst, const char *hmacpath)
{
_cleanup_free_ char *srcpath = strdup(src);
_cleanup_free_ char *dstpath = strdup(dst);
_cleanup_free_ char *srchmacname = NULL;
_cleanup_free_ char *dsthmacname = NULL;

if (!(srcpath && dstpath))
return -ENOMEM;

size_t dlen = dir_len(src);

if (endswith(src, ".hmac"))
Expand All @@ -648,16 +643,14 @@ static int hmac_install(const char *src, const char *dst, const char *hmacpath)
hmac_install(src, dst, "/lib64/hmaccalc");
}

srcpath[dlen] = '\0';
dstpath[dir_len(dst)] = '\0';
if (hmacpath) {
_asprintf(&srchmacname, "%s/%s.hmac", hmacpath, &src[dlen + 1]);
_asprintf(&dsthmacname, "%s/%s.hmac", hmacpath, &src[dlen + 1]);
} else {
_asprintf(&srchmacname, "%s/.%s.hmac", srcpath, &src[dlen + 1]);
_asprintf(&dsthmacname, "%s/.%s.hmac", dstpath, &src[dlen + 1]);
_asprintf(&srchmacname, "%.*s/.%s.hmac", (int)dlen, src, &src[dlen + 1]);
_asprintf(&dsthmacname, "%.*s/.%s.hmac", (int)dir_len(dst), dst, &src[dlen + 1]);
}
log_debug("hmac cp '%s' '%s')", srchmacname, dsthmacname);
log_debug("hmac cp '%s' '%s'", srchmacname, dsthmacname);
dracut_install(srchmacname, dsthmacname, false, false, true);
return 0;
}
Expand Down

0 comments on commit 77226cb

Please sign in to comment.