]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
perf(dracut-install): don't reallocate {src,dst}path in hmac_install()
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Wed, 27 Apr 2022 16:46:58 +0000 (18:46 +0200)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Wed, 28 Dec 2022 15:37:51 +0000 (16:37 +0100)
src/install/dracut-install.c

index 5944daa43ae6659a5bbe890036ffe023046c6e48..0703074569ac18392c8227adc332b677e813894b 100644 (file)
@@ -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"))
@@ -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;
 }