From 4c619758b2806ee6607af7b1d56943e547001e7a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 9 Jul 2019 13:55:16 -0700 Subject: [PATCH] Defend fingerprint against even-smarter LTO MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/pdumper.c (Fdump_emacs_portable, pdumper_load): Don’t cast volatile to non-volatile pointer, as that does not in general suffice to prevent a compiler from optimizing away memcmp and/or memcpy calls. Instead, copy the fingerprint by hand. --- src/pdumper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pdumper.c b/src/pdumper.c index 7d29d3c0c83..3d8531c6a43 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -4101,8 +4101,8 @@ types. */) ctx->header.magic[0] = '!'; /* Note that dump is incomplete. */ verify (sizeof (fingerprint) == sizeof (ctx->header.fingerprint)); - memcpy (ctx->header.fingerprint, (unsigned char *) fingerprint, - sizeof (fingerprint)); + for (int i = 0; i < sizeof fingerprint; i++) + ctx->header.fingerprint[i] = fingerprint[i]; const dump_off header_start = ctx->offset; dump_fingerprint ("dumping fingerprint", ctx->header.fingerprint); @@ -5360,10 +5360,12 @@ pdumper_load (const char *dump_filename) err = PDUMPER_LOAD_VERSION_MISMATCH; verify (sizeof (header->fingerprint) == sizeof (fingerprint)); - if (memcmp (header->fingerprint, (unsigned char *) fingerprint, - sizeof (fingerprint)) != 0) + unsigned char desired[sizeof fingerprint]; + for (int i = 0; i < sizeof fingerprint; i++) + desired[i] = fingerprint[i]; + if (memcmp (header->fingerprint, desired, sizeof desired) != 0) { - dump_fingerprint ("desired fingerprint", (unsigned char *) fingerprint); + dump_fingerprint ("desired fingerprint", desired); dump_fingerprint ("found fingerprint", header->fingerprint); goto out; } -- 2.39.5