]> xenbits.xensource.com Git - libvirt.git/commitdiff
polkit_driver: fix possible segfault
authorPavel Hrdina <phrdina@redhat.com>
Thu, 25 Sep 2014 09:13:29 +0000 (11:13 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 25 Sep 2014 10:53:37 +0000 (12:53 +0200)
The changes in commit c7542573 introduced possible segfault. Looking
deeper into the code and the original code before the patch series were
applied I think that we should report error for each function failure
and also we shouldn't call some of the function twice.

Found by coverity.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/access/viraccessdriverpolkit.c

index 2bc18429d66dd56cea177e354e6d1d55e3c1f2be..3136be7ea01c828125039367c535a162484e1281 100644 (file)
@@ -87,24 +87,22 @@ virAccessDriverPolkitGetCaller(const char *actionid,
                        actionid);
         return -1;
     }
-    if (virIdentityGetUNIXProcessID(identity, pid) < 0)
-        goto cleanup;
-    if (virIdentityGetUNIXProcessTime(identity, startTime) < 0)
-        goto cleanup;
-    if (virIdentityGetUNIXUserID(identity, uid) < 0)
-        goto cleanup;
 
-    if (!pid) {
+    if (virIdentityGetUNIXProcessID(identity, pid) < 0) {
         virAccessError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("No UNIX process ID available"));
         goto cleanup;
     }
-
-    if (virIdentityGetUNIXProcessTime(identity, startTime) < 0)
+    if (virIdentityGetUNIXProcessTime(identity, startTime) < 0) {
+        virAccessError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("No UNIX process start time available"));
         goto cleanup;
-
-    if (virIdentityGetUNIXUserID(identity, uid) < 0)
+    }
+    if (virIdentityGetUNIXUserID(identity, uid) < 0) {
+        virAccessError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("No UNIX caller UID available"));
         goto cleanup;
+    }
 
     ret = 0;