xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 for-4.15] tools/libxl: Work around unintialised variable libxl__domain_get_device_model_uid()
@ 2021-02-19 15:04 Andrew Cooper
  2021-02-19 16:35 ` Ian Jackson
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Cooper @ 2021-02-19 15:04 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson, Wei Liu, Anthony PERARD

Various version of gcc, when compiling with -Og, complain:

  libxl_dm.c: In function 'libxl__domain_get_device_model_uid':
  libxl_dm.c:256:12: error: 'kill_by_uid' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    256 |         if (kill_by_uid)
        |            ^

The logic is very tangled.  Set kill_by_uid on every path.

No funcational change.

Requested-by: Ian Jackson <iwj@xenproject.org>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Not-acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Ian Jackson <iwj@xenproject.org>
CC: Wei Liu <wl@xen.org>
CC: Anthony PERARD <anthony.perard@citrix.com>
---
 tools/libs/light/libxl_dm.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
index db4cec6a76..5309496c58 100644
--- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -152,13 +152,16 @@ static int libxl__domain_get_device_model_uid(libxl__gc *gc,
     user = b_info->device_model_user;
     if (user) {
         rc = userlookup_helper_getpwnam(gc, user, &user_pwbuf, &user_base);
-        if (rc)
+        if (rc) {
+            kill_by_uid = false;
             goto out;
+        }
 
         if (!user_base) {
             LOGD(ERROR, guest_domid, "Couldn't find device_model_user %s",
                  user);
             rc = ERROR_INVAL;
+            kill_by_uid = false;
             goto out;
         }
 
@@ -187,22 +190,29 @@ static int libxl__domain_get_device_model_uid(libxl__gc *gc,
      */
     rc = userlookup_helper_getpwnam(gc, LIBXL_QEMU_USER_RANGE_BASE,
                                          &user_pwbuf, &user_base);
-    if (rc)
+    if (rc) {
+        kill_by_uid = false;
         goto out;
+    }
+
     if (user_base) {
         struct passwd *user_clash, user_clash_pwbuf;
 
         intended_uid = user_base->pw_uid + guest_domid;
         rc = userlookup_helper_getpwuid(gc, intended_uid,
                                          &user_clash_pwbuf, &user_clash);
-        if (rc)
+        if (rc) {
+            kill_by_uid = false;
             goto out;
+        }
+
         if (user_clash) {
             LOGD(ERROR, guest_domid,
                  "wanted to use uid %ld (%s + %d) but that is user %s !",
                  (long)intended_uid, LIBXL_QEMU_USER_RANGE_BASE,
                  guest_domid, user_clash->pw_name);
             rc = ERROR_INVAL;
+            kill_by_uid = false;
             goto out;
         }
 
@@ -221,8 +231,11 @@ static int libxl__domain_get_device_model_uid(libxl__gc *gc,
      */
     user = LIBXL_QEMU_USER_SHARED;
     rc = userlookup_helper_getpwnam(gc, user, &user_pwbuf, &user_base);
-    if (rc)
+    if (rc) {
+        kill_by_uid = false;
         goto out;
+    }
+
     if (user_base) {
         LOGD(WARN, guest_domid, "Could not find user %s, falling back to %s",
              LIBXL_QEMU_USER_RANGE_BASE, LIBXL_QEMU_USER_SHARED);
@@ -240,6 +253,7 @@ static int libxl__domain_get_device_model_uid(libxl__gc *gc,
          "Could not find user %s or range base pseudo-user %s, cannot restrict",
          LIBXL_QEMU_USER_SHARED, LIBXL_QEMU_USER_RANGE_BASE);
     rc = ERROR_INVAL;
+    kill_by_uid = false;
 
 out:
     /* First, do a root check if appropriate */
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 for-4.15] tools/libxl: Work around unintialised variable libxl__domain_get_device_model_uid()
  2021-02-19 15:04 [PATCH v2 for-4.15] tools/libxl: Work around unintialised variable libxl__domain_get_device_model_uid() Andrew Cooper
@ 2021-02-19 16:35 ` Ian Jackson
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Jackson @ 2021-02-19 16:35 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Xen-devel, Wei Liu, Anthony PERARD

Andrew Cooper writes ("[PATCH v2 for-4.15] tools/libxl: Work around unintialised variable libxl__domain_get_device_model_uid()"):
> Various version of gcc, when compiling with -Og, complain:
> 
>   libxl_dm.c: In function 'libxl__domain_get_device_model_uid':
>   libxl_dm.c:256:12: error: 'kill_by_uid' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>     256 |         if (kill_by_uid)
>         |            ^
> 
> The logic is very tangled.  Set kill_by_uid on every path.
> 
> No funcational change.
> 
> Requested-by: Ian Jackson <iwj@xenproject.org>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Not-acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Ian Jackson <iwj@xenproject.org>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-19 16:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 15:04 [PATCH v2 for-4.15] tools/libxl: Work around unintialised variable libxl__domain_get_device_model_uid() Andrew Cooper
2021-02-19 16:35 ` 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).