From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>, Wei Liu <wei.liu2@citrix.com>
Subject: [PATCH] libxl: make sure string is null-terminated in libxl__prepare_sockaddr_un
Date: Wed, 22 Aug 2018 11:21:55 +0100 [thread overview]
Message-ID: <20180822102155.990-1-wei.liu2@citrix.com> (raw)
Coverity-ID: 1438472
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
---
tools/libxl/libxl_utils.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 5854717b11..e06f765699 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -1238,6 +1238,8 @@ int libxl__prepare_sockaddr_un(libxl__gc *gc,
struct sockaddr_un *un, const char *path,
const char *what)
{
+ size_t sz = sizeof(un->sun_path);
+
if (sizeof(un->sun_path) <= strlen(path)) {
LOG(ERROR, "UNIX socket path '%s' is too long for %s", path, what);
LOG(DEBUG, "Path must be less than %zu bytes", sizeof(un->sun_path));
@@ -1245,7 +1247,8 @@ int libxl__prepare_sockaddr_un(libxl__gc *gc,
}
memset(un, 0, sizeof(struct sockaddr_un));
un->sun_family = AF_UNIX;
- strncpy(un->sun_path, path, sizeof(un->sun_path));
+ strncpy(un->sun_path, path, sz);
+ un->sun_path[sz - 1] = '\0';
return 0;
}
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next reply other threads:[~2018-08-22 10:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-22 10:21 Wei Liu [this message]
2018-08-22 11:39 ` [PATCH] libxl: make sure string is null-terminated in libxl__prepare_sockaddr_un Ian Jackson
2018-08-22 13:44 ` Wei Liu
2018-08-22 14:33 ` Ian Jackson
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=20180822102155.990-1-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=xen-devel@lists.xenproject.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).