From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 2/2] common: elf: use memcmp for fixed-size comparison
Date: Mon, 5 Jan 2026 09:33:38 +0100 [thread overview]
Message-ID: <20260105083340.3254634-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260105083340.3254634-1-a.fatoum@barebox.org>
strncmp would only make sense if it were taking the size of buf as
argument, but it's taking the size of ELFMAG instead, which is a fixed 4
bytes. It's thus effectively equal to memcmp, so switch to using that
instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/elf.c b/common/elf.c
index e8126c9b64e7..18c541bf827e 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -201,7 +201,7 @@ static int load_elf_image_segments(struct elf_image *elf)
static int elf_check_image(struct elf_image *elf, void *buf)
{
- if (strncmp(buf, ELFMAG, SELFMAG)) {
+ if (memcmp(buf, ELFMAG, SELFMAG)) {
pr_err("ELF magic not found.\n");
return -EINVAL;
}
--
2.47.3
next prev parent reply other threads:[~2026-01-05 8:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-05 8:33 [PATCH 1/2] common: elf: use strdup_const for symmetry Ahmad Fatoum
2026-01-05 8:33 ` Ahmad Fatoum [this message]
2026-01-06 7:39 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260105083340.3254634-2-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox