From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Keir Fraser <keir@xen.org>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH] hvmloader/smbios: Change strncpy to memcpy for anchor strings.
Date: Mon, 23 Sep 2013 19:22:09 +0100 [thread overview]
Message-ID: <1379960529-4978-1-git-send-email-andrew.cooper3@citrix.com> (raw)
Coverity complains about the use of strncpy() to completely fill the anchor
strings, resulting in an unterminated string.
Although the strncpy result is correct, the anchor strings are not strings in
the C sense, and use of memcpy is the prevaling style elsewhere in hvmloader
anyway.
While tidying up the style in this function, also remove some trailing
whitespace and gratuitous cast.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>
---
tools/firmware/hvmloader/smbios.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/smbios.c
index 9f292cc..900f4e7 100644
--- a/tools/firmware/hvmloader/smbios.c
+++ b/tools/firmware/hvmloader/smbios.c
@@ -347,18 +347,19 @@ smbios_entry_point_init(void *start,
{
uint8_t sum;
int i;
- struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
+ struct smbios_entry_point *ep = start;
memset(ep, 0, sizeof(*ep));
- strncpy(ep->anchor_string, "_SM_", 4);
+ memcpy(ep->anchor_string, "_SM_", sizeof(ep->anchor_string));
ep->length = 0x1f;
ep->smbios_major_version = 2;
ep->smbios_minor_version = 4;
ep->max_structure_size = max_structure_size;
ep->entry_point_revision = 0;
- strncpy(ep->intermediate_anchor_string, "_DMI_", 5);
-
+ memcpy(ep->intermediate_anchor_string, "_DMI_",
+ sizeof(ep->intermediate_anchor_string));
+
ep->structure_table_length = structure_table_length;
ep->structure_table_address = structure_table_address;
ep->number_of_structures = number_of_structures;
--
1.7.10.4
next reply other threads:[~2013-09-23 18:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-23 18:22 Andrew Cooper [this message]
2013-09-24 9:14 ` [PATCH] hvmloader/smbios: Change strncpy to memcpy for anchor strings Paul Durrant
2013-09-24 9:39 ` Jan Beulich
2013-09-24 10:11 ` Keir Fraser
2013-09-24 10:18 ` Jan Beulich
2013-09-26 13:52 ` Andrew Cooper
2013-09-26 19:13 ` Keir Fraser
2013-09-24 9:40 ` Jan Beulich
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=1379960529-4978-1-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=keir@xen.org \
--cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).