Skip to contentSkip to conversation

tools/xl: fix uninitialized variable in xl_vdispl

PATCH Superseded Doug Goldstein 5 participants 6 messages Mar 13, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xl: fix uninitialized variable in xl_vdispl

The code added in 7a48622a78a0b452e8afa55b8442c958abd226a7 could use rc uninitialized in main_vdisplattach().

---
CC: Oleksandr Grytsov <[email protected]>

---
 tools/xl/xl_vdispl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xl/xl_vdispl.c +1 -1
index 3cc99b6aed..8fbad5be68 100644
@@ -25,7 +25,7 @@
 int main_vdisplattach(int argc, char **argv)
 {
     int opt;
-    int rc;
+    int rc = ERROR_FAIL;
     uint32_t domid;
     libxl_device_vdispl vdispl;
 
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.03.18 at 05:43, <[email protected]> wrote:

The code added in 7a48622a78a0b452e8afa55b8442c958abd226a7 could use rc uninitialized in main_vdisplattach().

---
CC: Oleksandr Grytsov <[email protected]>

---
 tools/xl/xl_vdispl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Please trim your Cc list - I've removed all individuals here, and I don't see why you've copied all REST maintainers when this is clearly a pure tool stack change.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 15 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.03.18 at 05:43, <[email protected]> wrote:

The code added in 7a48622a78a0b452e8afa55b8442c958abd226a7 could use rc uninitialized in main_vdisplattach().

---
CC: Oleksandr Grytsov <[email protected]>

---
 tools/xl/xl_vdispl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Please trim your Cc list - I've removed all individuals here, and I don't see why you've copied all REST maintainers when this is clearly a pure tool stack change.

Quoted 8 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Hi, Doug,

Thanks for pointing it out.

The implementation is done according to CODING_STYLE document (see ERROR HANDLING)
which requests to define return value rc uninitialized. The only path where rc is uninitialized it is
when dryrun_only set to true. So, proper fix should be:

    if (dryrun_only) {
        char *json = libxl_device_vdispl_to_json(ctx, &vdispl);
        printf("vdispl: %s\n", json);
        free(json);
+      rc = 0;
        goto out;
    }
Signature · 2 lines
Best Regards,
Oleksandr Grytsov.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Jan Beulich
Quoted 11 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.03.18 at 05:43, <[email protected]> wrote:

The code added in 7a48622a78a0b452e8afa55b8442c958abd226a7 could use rc uninitialized in main_vdisplattach().

---
CC: Oleksandr Grytsov <[email protected]>

---
 tools/xl/xl_vdispl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 6 lines

Please trim your Cc list - I've removed all individuals here, and I don't see why you've copied all REST maintainers when this is clearly a pure tool stack change.

Jan

Yea it was a mistake on my part. Submitting patches late at night caused me to add a -f to get_maintainer.pl

Signature · 6 lines
Doug Goldstein

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw
In reply to Doug Goldstein
Quoted 4 lines · Doug Goldstein

The code added in 7a48622a78a0b452e8afa55b8442c958abd226a7 could use rc uninitialized in main_vdisplattach().

It looks like that was designed on purpose to use the uninitialized warnings to catch paths where the rc wasn't specifically set.

The only path where it's not set is if dryrun_only is true; and in that case, we probably actually want it to succeed, not fail.

No matter what, rc = 0 should be added to the dryrun_only path. If we want to make ERROR_FAIL the default, then the various places rc is set to ERROR_FAIL should be removed.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 9 lines · George Dunlap
Quoted 4 lines · Doug Goldstein

The code added in 7a48622a78a0b452e8afa55b8442c958abd226a7 could use rc uninitialized in main_vdisplattach().

It looks like that was designed on purpose to use the uninitialized warnings to catch paths where the rc wasn't specifically set.

Quoted 6 lines

The only path where it's not set is if dryrun_only is true; and in that case, we probably actually want it to succeed, not fail.

No matter what, rc = 0 should be added to the dryrun_only path. If we want to make ERROR_FAIL the default, then the various places rc is set to ERROR_FAIL should be removed.

Yeah, CODING_STYLE dictates rc to not be initialised.

Setting rc = 0 in the appropriate place is the right solution.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel