* [PATCH 1/4] libxenstat: check xc_interface_open return value
2015-04-08 15:01 [PATCH 0/4] libxenstat bug fixes and cleanups Wei Liu
@ 2015-04-08 15:01 ` Wei Liu
2015-04-08 15:21 ` Andrew Cooper
2015-04-08 15:01 ` [PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL Wei Liu
` (2 subsequent siblings)
3 siblings, 1 reply; 14+ messages in thread
From: Wei Liu @ 2015-04-08 15:01 UTC (permalink / raw)
To: xen-devel
Cc: Ian Jackson, andrew.cooper3, Wei Liu, Ian Campbell,
Charles Arnold
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Charles Arnold <carnold@suse.com>
---
tools/xenstat/libxenstat/src/xenstat_qmp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
index 2cb99e9..f3aeec4 100644
--- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
+++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
@@ -366,6 +366,8 @@ static xc_domaininfo_t *get_domain_ids(int *num_doms)
if (dominfo == NULL)
return NULL;
xc_handle = xc_interface_open(0,0,0);
+ if (xc_handle == NULL)
+ return NULL;
*num_doms = xc_domain_getinfolist(xc_handle, 0, 1024, dominfo);
xc_interface_close(xc_handle);
return dominfo;
--
1.9.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 1/4] libxenstat: check xc_interface_open return value
2015-04-08 15:01 ` [PATCH 1/4] libxenstat: check xc_interface_open return value Wei Liu
@ 2015-04-08 15:21 ` Andrew Cooper
2015-04-08 15:47 ` Wei Liu
0 siblings, 1 reply; 14+ messages in thread
From: Andrew Cooper @ 2015-04-08 15:21 UTC (permalink / raw)
To: Wei Liu, xen-devel; +Cc: Charles Arnold, Ian Jackson, Ian Campbell
On 08/04/15 16:01, Wei Liu wrote:
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Charles Arnold <carnold@suse.com>
The xenstat handle passed around already has an open xc_handle. That
should be reused rather than opening a new one every time we want to get
a list of domain ids.
~Andrew
> ---
> tools/xenstat/libxenstat/src/xenstat_qmp.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> index 2cb99e9..f3aeec4 100644
> --- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
> +++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> @@ -366,6 +366,8 @@ static xc_domaininfo_t *get_domain_ids(int *num_doms)
> if (dominfo == NULL)
> return NULL;
> xc_handle = xc_interface_open(0,0,0);
> + if (xc_handle == NULL)
> + return NULL;
> *num_doms = xc_domain_getinfolist(xc_handle, 0, 1024, dominfo);
> xc_interface_close(xc_handle);
> return dominfo;
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/4] libxenstat: check xc_interface_open return value
2015-04-08 15:21 ` Andrew Cooper
@ 2015-04-08 15:47 ` Wei Liu
0 siblings, 0 replies; 14+ messages in thread
From: Wei Liu @ 2015-04-08 15:47 UTC (permalink / raw)
To: Andrew Cooper
Cc: Charles Arnold, Ian Jackson, Wei Liu, Ian Campbell, xen-devel
On Wed, Apr 08, 2015 at 04:21:56PM +0100, Andrew Cooper wrote:
> On 08/04/15 16:01, Wei Liu wrote:
> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> > Cc: Charles Arnold <carnold@suse.com>
>
> The xenstat handle passed around already has an open xc_handle. That
> should be reused rather than opening a new one every time we want to get
> a list of domain ids.
>
Yes, you're right. I will use that.
Wei.
> ~Andrew
>
> > ---
> > tools/xenstat/libxenstat/src/xenstat_qmp.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> > index 2cb99e9..f3aeec4 100644
> > --- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
> > +++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> > @@ -366,6 +366,8 @@ static xc_domaininfo_t *get_domain_ids(int *num_doms)
> > if (dominfo == NULL)
> > return NULL;
> > xc_handle = xc_interface_open(0,0,0);
> > + if (xc_handle == NULL)
> > + return NULL;
> > *num_doms = xc_domain_getinfolist(xc_handle, 0, 1024, dominfo);
> > xc_interface_close(xc_handle);
> > return dominfo;
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL
2015-04-08 15:01 [PATCH 0/4] libxenstat bug fixes and cleanups Wei Liu
2015-04-08 15:01 ` [PATCH 1/4] libxenstat: check xc_interface_open return value Wei Liu
@ 2015-04-08 15:01 ` Wei Liu
2015-04-08 15:22 ` Andrew Cooper
2015-04-08 15:47 ` Ian Jackson
2015-04-08 15:01 ` [PATCH 3/4] libxenstat: always free qmp_stats Wei Liu
2015-04-08 15:01 ` [PATCH 4/4] libxenstat: qmp_read fix and cleanup Wei Liu
3 siblings, 2 replies; 14+ messages in thread
From: Wei Liu @ 2015-04-08 15:01 UTC (permalink / raw)
To: xen-devel
Cc: Ian Jackson, andrew.cooper3, Wei Liu, Ian Campbell,
Charles Arnold
Passing NULL to strcmp can cause segmentation fault. Continue in that
case.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Charles Arnold <carnold@suse.com>
---
tools/xenstat/libxenstat/src/xenstat_qmp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
index f3aeec4..6bfbc2f 100644
--- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
+++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
@@ -110,7 +110,7 @@ static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd)
ptr[0] = qblock[QMP_BLOCK_DEVICE]; /* "device" */
if ((dev_obj = yajl_tree_get(n, ptr, yajl_t_any)) != NULL) {
tmp = YAJL_GET_STRING(dev_obj);
- if (strcmp(qmp_devname, tmp))
+ if (!tmp || strcmp(qmp_devname, tmp))
continue;
}
else
--
1.9.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL
2015-04-08 15:01 ` [PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL Wei Liu
@ 2015-04-08 15:22 ` Andrew Cooper
2015-04-08 15:47 ` Ian Jackson
1 sibling, 0 replies; 14+ messages in thread
From: Andrew Cooper @ 2015-04-08 15:22 UTC (permalink / raw)
To: Wei Liu, xen-devel; +Cc: Charles Arnold, Ian Jackson, Ian Campbell
On 08/04/15 16:01, Wei Liu wrote:
> Passing NULL to strcmp can cause segmentation fault. Continue in that
> case.
>
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Charles Arnold <carnold@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> tools/xenstat/libxenstat/src/xenstat_qmp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> index f3aeec4..6bfbc2f 100644
> --- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
> +++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> @@ -110,7 +110,7 @@ static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd)
> ptr[0] = qblock[QMP_BLOCK_DEVICE]; /* "device" */
> if ((dev_obj = yajl_tree_get(n, ptr, yajl_t_any)) != NULL) {
> tmp = YAJL_GET_STRING(dev_obj);
> - if (strcmp(qmp_devname, tmp))
> + if (!tmp || strcmp(qmp_devname, tmp))
> continue;
> }
> else
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL
2015-04-08 15:01 ` [PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL Wei Liu
2015-04-08 15:22 ` Andrew Cooper
@ 2015-04-08 15:47 ` Ian Jackson
1 sibling, 0 replies; 14+ messages in thread
From: Ian Jackson @ 2015-04-08 15:47 UTC (permalink / raw)
To: Wei Liu; +Cc: Charles Arnold, andrew.cooper3, Ian Campbell, xen-devel
Wei Liu writes ("[PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL"):
> Passing NULL to strcmp can cause segmentation fault. Continue in that
> case.
>
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Charles Arnold <carnold@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/4] libxenstat: always free qmp_stats
2015-04-08 15:01 [PATCH 0/4] libxenstat bug fixes and cleanups Wei Liu
2015-04-08 15:01 ` [PATCH 1/4] libxenstat: check xc_interface_open return value Wei Liu
2015-04-08 15:01 ` [PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL Wei Liu
@ 2015-04-08 15:01 ` Wei Liu
2015-04-08 15:49 ` Ian Jackson
2015-04-08 15:01 ` [PATCH 4/4] libxenstat: qmp_read fix and cleanup Wei Liu
3 siblings, 1 reply; 14+ messages in thread
From: Wei Liu @ 2015-04-08 15:01 UTC (permalink / raw)
To: xen-devel
Cc: Ian Jackson, andrew.cooper3, Wei Liu, Ian Campbell,
Charles Arnold
Originally qmp_stats is only freed in failure path and leaked in success
path.
Instead of wiring up the success path, rearrange the code a bit to
always free qmp_stats before checking if info is NULL.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Charles Arnold <carnold@suse.com>
---
tools/xenstat/libxenstat/src/xenstat_qmp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
index 6bfbc2f..e4f343b 100644
--- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
+++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
@@ -95,10 +95,10 @@ static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd)
return NULL;
/* Use libyajl version 2.0.3 or newer for the tree parser feature with bug fixes */
- if ((info = yajl_tree_parse((char *)qmp_stats, NULL, 0)) == NULL) {
- free(qmp_stats);
+ info = yajl_tree_parse((char *)qmp_stats, NULL, 0);
+ free(qmp_stats);
+ if (info == NULL)
return NULL;
- }
ptr[0] = qblock[QMP_BLOCK_RETURN]; /* "return" */
if ((ret_obj = yajl_tree_get(info, ptr, yajl_t_array)) == NULL)
--
1.9.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 3/4] libxenstat: always free qmp_stats
2015-04-08 15:01 ` [PATCH 3/4] libxenstat: always free qmp_stats Wei Liu
@ 2015-04-08 15:49 ` Ian Jackson
2015-04-08 15:56 ` Wei Liu
0 siblings, 1 reply; 14+ messages in thread
From: Ian Jackson @ 2015-04-08 15:49 UTC (permalink / raw)
To: Wei Liu; +Cc: Charles Arnold, andrew.cooper3, Ian Campbell, xen-devel
Wei Liu writes ("[PATCH 3/4] libxenstat: always free qmp_stats"):
> Originally qmp_stats is only freed in failure path and leaked in success
> path.
>
> Instead of wiring up the success path, rearrange the code a bit to
> always free qmp_stats before checking if info is NULL.
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Having said that, I am not a great fan of the error handling cleanup
style adopted in this code in general. The ownership and lifetime of
the various allocated objects has to be inferred by reading the code
in detail.
Ian.
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 3/4] libxenstat: always free qmp_stats
2015-04-08 15:49 ` Ian Jackson
@ 2015-04-08 15:56 ` Wei Liu
0 siblings, 0 replies; 14+ messages in thread
From: Wei Liu @ 2015-04-08 15:56 UTC (permalink / raw)
To: Ian Jackson
Cc: Charles Arnold, andrew.cooper3, Wei Liu, Ian Campbell, xen-devel
On Wed, Apr 08, 2015 at 04:49:58PM +0100, Ian Jackson wrote:
> Wei Liu writes ("[PATCH 3/4] libxenstat: always free qmp_stats"):
> > Originally qmp_stats is only freed in failure path and leaked in success
> > path.
> >
> > Instead of wiring up the success path, rearrange the code a bit to
> > always free qmp_stats before checking if info is NULL.
>
> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
>
> Having said that, I am not a great fan of the error handling cleanup
> style adopted in this code in general. The ownership and lifetime of
> the various allocated objects has to be inferred by reading the code
> in detail.
>
Yeah... I'm with you. On the other hand I want my bug fix patch to be as
small as possible. Changing this function to goto style will make the
patch a lot bigger. I think we can clean this function up with another
patch if anyone feels keen enough.
Wei.
> Ian.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/4] libxenstat: qmp_read fix and cleanup
2015-04-08 15:01 [PATCH 0/4] libxenstat bug fixes and cleanups Wei Liu
` (2 preceding siblings ...)
2015-04-08 15:01 ` [PATCH 3/4] libxenstat: always free qmp_stats Wei Liu
@ 2015-04-08 15:01 ` Wei Liu
2015-04-08 15:25 ` Andrew Cooper
3 siblings, 1 reply; 14+ messages in thread
From: Wei Liu @ 2015-04-08 15:01 UTC (permalink / raw)
To: xen-devel
Cc: Ian Jackson, andrew.cooper3, Wei Liu, Ian Campbell,
Charles Arnold
The second argument of poll(2) is the number of file descriptors. POLLIN
is defined as 1 so it happens to work.
Also do two cleanups while I was there:
1. There is only one fd, so a one-element array is enough.
2. Initialise pfd to make code linter happy.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Charles Arnold <carnold@suse.com>
---
tools/xenstat/libxenstat/src/xenstat_qmp.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
index e4f343b..260cd34 100644
--- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
+++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
@@ -289,13 +289,14 @@ static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
static int qmp_read(int qfd, unsigned char **qstats)
{
unsigned char buf[1024], *ptr;
- struct pollfd pfd[2];
+ struct pollfd pfd[1];
int n, qsize = 0;
*qstats = NULL;
+ memset(pfd, 0, sizeof(pfd));
pfd[0].fd = qfd;
pfd[0].events = POLLIN;
- while ((n = poll(pfd, POLLIN, 10)) > 0) {
+ while ((n = poll(pfd, 1, 10)) > 0) {
if (pfd[0].revents & POLLIN) {
if ((n = read(qfd, buf, sizeof(buf))) < 0) {
free(*qstats);
@@ -311,6 +312,9 @@ static int qmp_read(int qfd, unsigned char **qstats)
ptr[qsize] = 0;
*qstats = ptr;
}
+ memset(pfd, 0, sizeof(pfd));
+ pfd[0].fd = qfd;
+ pfd[0].events = POLLIN;
}
return 1;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 4/4] libxenstat: qmp_read fix and cleanup
2015-04-08 15:01 ` [PATCH 4/4] libxenstat: qmp_read fix and cleanup Wei Liu
@ 2015-04-08 15:25 ` Andrew Cooper
2015-04-08 15:47 ` Wei Liu
2015-04-08 15:52 ` Ian Jackson
0 siblings, 2 replies; 14+ messages in thread
From: Andrew Cooper @ 2015-04-08 15:25 UTC (permalink / raw)
To: Wei Liu, xen-devel; +Cc: Charles Arnold, Ian Jackson, Ian Campbell
On 08/04/15 16:01, Wei Liu wrote:
> The second argument of poll(2) is the number of file descriptors. POLLIN
> is defined as 1 so it happens to work.
>
> Also do two cleanups while I was there:
> 1. There is only one fd, so a one-element array is enough.
> 2. Initialise pfd to make code linter happy.
>
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Charles Arnold <carnold@suse.com>
> ---
> tools/xenstat/libxenstat/src/xenstat_qmp.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> index e4f343b..260cd34 100644
> --- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
> +++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> @@ -289,13 +289,14 @@ static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
> static int qmp_read(int qfd, unsigned char **qstats)
> {
> unsigned char buf[1024], *ptr;
> - struct pollfd pfd[2];
> + struct pollfd pfd[1];
> int n, qsize = 0;
>
> *qstats = NULL;
> + memset(pfd, 0, sizeof(pfd));
> pfd[0].fd = qfd;
> pfd[0].events = POLLIN;
> - while ((n = poll(pfd, POLLIN, 10)) > 0) {
> + while ((n = poll(pfd, 1, 10)) > 0) {
> if (pfd[0].revents & POLLIN) {
> if ((n = read(qfd, buf, sizeof(buf))) < 0) {
> free(*qstats);
> @@ -311,6 +312,9 @@ static int qmp_read(int qfd, unsigned char **qstats)
> ptr[qsize] = 0;
> *qstats = ptr;
> }
> + memset(pfd, 0, sizeof(pfd));
> + pfd[0].fd = qfd;
> + pfd[0].events = POLLIN;
I don't think this is necessary. .fd and .events should be untouched by
poll().
Ignore the complaint about revents being uninitialised. That is because
Coverity doesn't have a model for poll(), and doesn't know that poll()
writes to revents.
I was going to find some copious free time to correctly model poll(),
which will fix several related defects.
~Andrew
> }
> return 1;
> }
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 4/4] libxenstat: qmp_read fix and cleanup
2015-04-08 15:25 ` Andrew Cooper
@ 2015-04-08 15:47 ` Wei Liu
2015-04-08 15:52 ` Ian Jackson
1 sibling, 0 replies; 14+ messages in thread
From: Wei Liu @ 2015-04-08 15:47 UTC (permalink / raw)
To: Andrew Cooper
Cc: Charles Arnold, Ian Jackson, Wei Liu, Ian Campbell, xen-devel
On Wed, Apr 08, 2015 at 04:25:06PM +0100, Andrew Cooper wrote:
> On 08/04/15 16:01, Wei Liu wrote:
> > The second argument of poll(2) is the number of file descriptors. POLLIN
> > is defined as 1 so it happens to work.
> >
> > Also do two cleanups while I was there:
> > 1. There is only one fd, so a one-element array is enough.
> > 2. Initialise pfd to make code linter happy.
> >
> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> > Cc: Charles Arnold <carnold@suse.com>
> > ---
> > tools/xenstat/libxenstat/src/xenstat_qmp.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> > index e4f343b..260cd34 100644
> > --- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
> > +++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> > @@ -289,13 +289,14 @@ static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
> > static int qmp_read(int qfd, unsigned char **qstats)
> > {
> > unsigned char buf[1024], *ptr;
> > - struct pollfd pfd[2];
> > + struct pollfd pfd[1];
> > int n, qsize = 0;
> >
> > *qstats = NULL;
> > + memset(pfd, 0, sizeof(pfd));
> > pfd[0].fd = qfd;
> > pfd[0].events = POLLIN;
> > - while ((n = poll(pfd, POLLIN, 10)) > 0) {
> > + while ((n = poll(pfd, 1, 10)) > 0) {
> > if (pfd[0].revents & POLLIN) {
> > if ((n = read(qfd, buf, sizeof(buf))) < 0) {
> > free(*qstats);
> > @@ -311,6 +312,9 @@ static int qmp_read(int qfd, unsigned char **qstats)
> > ptr[qsize] = 0;
> > *qstats = ptr;
> > }
> > + memset(pfd, 0, sizeof(pfd));
> > + pfd[0].fd = qfd;
> > + pfd[0].events = POLLIN;
>
> I don't think this is necessary. .fd and .events should be untouched by
> poll().
>
> Ignore the complaint about revents being uninitialised. That is because
> Coverity doesn't have a model for poll(), and doesn't know that poll()
> writes to revents.
>
Sure.
> I was going to find some copious free time to correctly model poll(),
> which will fix several related defects.
>
That would be good!
Wei.
> ~Andrew
>
> > }
> > return 1;
> > }
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 4/4] libxenstat: qmp_read fix and cleanup
2015-04-08 15:25 ` Andrew Cooper
2015-04-08 15:47 ` Wei Liu
@ 2015-04-08 15:52 ` Ian Jackson
1 sibling, 0 replies; 14+ messages in thread
From: Ian Jackson @ 2015-04-08 15:52 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Charles Arnold, Wei Liu, Ian Campbell, xen-devel
Andrew Cooper writes ("Re: [PATCH 4/4] libxenstat: qmp_read fix and cleanup"):
> On 08/04/15 16:01, Wei Liu wrote:
> > The second argument of poll(2) is the number of file descriptors. POLLIN
> > is defined as 1 so it happens to work.
...
> > @@ -311,6 +312,9 @@ static int qmp_read(int qfd, unsigned char **qstats)
> > ptr[qsize] = 0;
> > *qstats = ptr;
> > }
> > + memset(pfd, 0, sizeof(pfd));
> > + pfd[0].fd = qfd;
> > + pfd[0].events = POLLIN;
>
> I don't think this is necessary. .fd and .events should be untouched by
> poll().
Indeed.
> Ignore the complaint about revents being uninitialised. That is because
> Coverity doesn't have a model for poll(), and doesn't know that poll()
> writes to revents.
I would be happy with the patch either with or without the memset.
Ian.
^ permalink raw reply [flat|nested] 14+ messages in thread