Change in vdsm[master]: virt: Don't expose GuestAgent.guestInfo directly

mzamazal at redhat.com mzamazal at redhat.com
Thu Jan 7 12:57:13 UTC 2016


Milan Zamazal has uploaded a new change for review.

Change subject: virt: Don't expose GuestAgent.guestInfo directly
......................................................................

virt: Don't expose GuestAgent.guestInfo directly

GuestInfo.getGuestInfo returns its guestInfo dict attribute directly, so
the callers may modify it.  guestInfo is a public attribute so it
shouldn't be a problem in theory as it's possible to modify that
attribute without calling getGuestInfo.  But guestInfo isn't used
anywhere outside GuestAgent and should be probably changed to a private
attribute.

If we offer guestInfo for modification outside GuestInfo then it may be
indeed modified, perhaps without realizing about modification of the
internal GuestInfo structure.  That actually already happens in
Vm._getGuestStats and causes incorrect memUsage value reported in case
of repeated invocations.

The safest approach to the problem is to return a copy of guestInfo from
getGuestInfo.

Change-Id: Ie48c697300e4feeb513dc662c2d1d3d8c21f0af9
Bug-Url: https://bugzilla.redhat.com/1295428
Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
---
M vdsm/virt/guestagent.py
1 file changed, 2 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/08/51508/1

diff --git a/vdsm/virt/guestagent.py b/vdsm/virt/guestagent.py
index 35a6fdb..d1d824c 100644
--- a/vdsm/virt/guestagent.py
+++ b/vdsm/virt/guestagent.py
@@ -19,6 +19,7 @@
 #
 
 import array
+import copy
 import logging
 import time
 import socket
@@ -357,7 +358,7 @@
 
     def getGuestInfo(self):
         if self.isResponsive():
-            return self.guestInfo
+            return copy.copy(self.guestInfo)
         else:
             return {
                 'username': 'Unknown',


-- 
To view, visit https://gerrit.ovirt.org/51508
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie48c697300e4feeb513dc662c2d1d3d8c21f0af9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Milan Zamazal <mzamazal at redhat.com>


More information about the vdsm-patches mailing list