* [PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime
@ 2016-02-17 10:34 Ian Campbell
2016-02-17 10:34 ` [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime Ian Campbell
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Ian Campbell @ 2016-02-17 10:34 UTC (permalink / raw)
To: ian.jackson, wei.liu2, xen-devel; +Cc: Ian Campbell
Dom0 is handled separately (via print_dom0_uptime) and the domU
variant doesn't work for dom0 since libxl_vm_get_start_time() doesn't.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
tools/libxl/xl_cmdimpl.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index f38e3dd..89fa42c 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -7055,8 +7055,10 @@ static void print_uptime(int short_mode, uint32_t doms[], int nb_doms)
fprintf(stderr, "Could not list vms.\n");
return;
}
- for (i = 0; i < nb_vm; i++)
+ for (i = 0; i < nb_vm; i++) {
+ if (info[i].domid == 0) continue;
print_domU_uptime(info[i].domid, short_mode, now);
+ }
libxl_vminfo_list_free(info, nb_vm);
} else {
for (i = 0; i < nb_doms; i++) {
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime
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
2016-03-01 16:11 ` 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
2 siblings, 1 reply; 5+ messages in thread
From: Ian Campbell @ 2016-02-17 10:34 UTC (permalink / raw)
To: ian.jackson, wei.liu2, xen-devel; +Cc: Ian Campbell
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime
2016-02-17 10:34 [PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime Ian Campbell
2016-02-17 10:34 ` [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime Ian Campbell
@ 2016-02-23 10:30 ` Ian Campbell
2016-03-01 16:10 ` Ian Jackson
2 siblings, 0 replies; 5+ messages in thread
From: Ian Campbell @ 2016-02-23 10:30 UTC (permalink / raw)
To: ian.jackson, wei.liu2, xen-devel
On Wed, 2016-02-17 at 10:34 +0000, Ian Campbell wrote:
> Dom0 is handled separately (via print_dom0_uptime) and the domU
> variant doesn't work for dom0 since libxl_vm_get_start_time() doesn't.
>
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Ping? (and for 2/2 "xl: NULL terminate buf when reading dom0 /proc/uptime")
> ---
> tools/libxl/xl_cmdimpl.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index f38e3dd..89fa42c 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -7055,8 +7055,10 @@ static void print_uptime(int short_mode, uint32_t
> doms[], int nb_doms)
> fprintf(stderr, "Could not list vms.\n");
> return;
> }
> - for (i = 0; i < nb_vm; i++)
> + for (i = 0; i < nb_vm; i++) {
> + if (info[i].domid == 0) continue;
> print_domU_uptime(info[i].domid, short_mode, now);
> + }
> libxl_vminfo_list_free(info, nb_vm);
> } else {
> for (i = 0; i < nb_doms; i++) {
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime
2016-02-17 10:34 [PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime Ian Campbell
2016-02-17 10:34 ` [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime Ian Campbell
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
2 siblings, 0 replies; 5+ messages in thread
From: Ian Jackson @ 2016-03-01 16:10 UTC (permalink / raw)
To: wei.liu2, xen-devel
Ian Campbell writes ("[PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime"):
> Dom0 is handled separately (via print_dom0_uptime) and the domU
> variant doesn't work for dom0 since libxl_vm_get_start_time() doesn't.
>
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
and queued
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime
2016-02-17 10:34 ` [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime Ian Campbell
@ 2016-03-01 16:11 ` Ian Jackson
0 siblings, 0 replies; 5+ messages in thread
From: Ian Jackson @ 2016-03-01 16:11 UTC (permalink / raw)
To: wei.liu2, xen-devel
Ian Campbell writes ("[PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime"):
> 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.
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
and queued
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-03-01 16:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-17 10:34 [PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime Ian Campbell
2016-02-17 10:34 ` [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime Ian Campbell
2016-03-01 16:11 ` 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
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).