Skip to content

Commit 77226cb

Browse files
nabijaczleweliaafeijoo-suse
authored andcommitted
perf(dracut-install): don't reallocate {src,dst}path in hmac_install()
1 parent a20556f commit 77226cb

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/install/dracut-install.c

+3-10
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,9 @@ static int resolve_deps(const char *src)
628628
/* Install ".<filename>.hmac" file for FIPS self-checks */
629629
static int hmac_install(const char *src, const char *dst, const char *hmacpath)
630630
{
631-
_cleanup_free_ char *srcpath = strdup(src);
632-
_cleanup_free_ char *dstpath = strdup(dst);
633631
_cleanup_free_ char *srchmacname = NULL;
634632
_cleanup_free_ char *dsthmacname = NULL;
635633

636-
if (!(srcpath && dstpath))
637-
return -ENOMEM;
638-
639634
size_t dlen = dir_len(src);
640635

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

651-
srcpath[dlen] = '\0';
652-
dstpath[dir_len(dst)] = '\0';
653646
if (hmacpath) {
654647
_asprintf(&srchmacname, "%s/%s.hmac", hmacpath, &src[dlen + 1]);
655648
_asprintf(&dsthmacname, "%s/%s.hmac", hmacpath, &src[dlen + 1]);
656649
} else {
657-
_asprintf(&srchmacname, "%s/.%s.hmac", srcpath, &src[dlen + 1]);
658-
_asprintf(&dsthmacname, "%s/.%s.hmac", dstpath, &src[dlen + 1]);
650+
_asprintf(&srchmacname, "%.*s/.%s.hmac", (int)dlen, src, &src[dlen + 1]);
651+
_asprintf(&dsthmacname, "%.*s/.%s.hmac", (int)dir_len(dst), dst, &src[dlen + 1]);
659652
}
660-
log_debug("hmac cp '%s' '%s')", srchmacname, dsthmacname);
653+
log_debug("hmac cp '%s' '%s'", srchmacname, dsthmacname);
661654
dracut_install(srchmacname, dsthmacname, false, false, true);
662655
return 0;
663656
}

0 commit comments

Comments
 (0)