From: Ian Campbell <ian.campbell@citrix.com>
To: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, xen-devel@lists.xen.org
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime
Date: Wed, 17 Feb 2016 10:34:24 +0000 [thread overview]
Message-ID: <1455705264-17744-2-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1455705264-17744-1-git-send-email-ian.campbell@citrix.com>
The contents of /proc/uptime is typically something like "80164.57
640617.58", so the existing 512 byte buffer is more than large enoguh,
so reduce its effective size to 511 bytes and ensure we include a
NULL.
Otherwise Coverity points out that we pass a potentially unterminated
string to strtok. In practice this likely doesn't actually cause
issues (at least on Linux) because the
string should always contain a space so we will stop parsing.
CID: 105590
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
tools/libxl/xl_cmdimpl.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 89fa42c..31cea0f 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -6959,6 +6959,7 @@ static char *current_time_to_string(time_t now)
static void print_dom0_uptime(int short_mode, time_t now)
{
int fd;
+ ssize_t nr;
char buf[512];
uint32_t uptime = 0;
char *uptime_str = NULL;
@@ -6969,12 +6970,15 @@ static void print_dom0_uptime(int short_mode, time_t now)
if (fd == -1)
goto err;
- if (read(fd, buf, sizeof(buf)) == -1) {
+ nr = read(fd, buf, sizeof(buf) - 1);
+ if (nr == -1) {
close(fd);
goto err;
}
close(fd);
+ buf[nr] = '\0';
+
strtok(buf, " ");
uptime = strtoul(buf, NULL, 10);
--
2.1.4
next prev parent reply other threads:[~2016-02-17 10:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 10:34 [PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime Ian Campbell
2016-02-17 10:34 ` Ian Campbell [this message]
2016-03-01 16:11 ` [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime Ian Jackson
2016-02-23 10:30 ` [PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime Ian Campbell
2016-03-01 16:10 ` 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=1455705264-17744-2-git-send-email-ian.campbell@citrix.com \
--to=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--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).