[PATCH 04/13] security: Fix return types of .probe callbacks

Michal Privoznik posted 13 patches 1 year, 9 months ago
There is a newer version of this series
[PATCH 04/13] security: Fix return types of .probe callbacks
Posted by Michal Privoznik 1 year, 9 months ago
The .probe member of virSecurityDriver struct is declared to
return virSecurityDriverStatus enum. But there are two instances
(AppArmorSecurityManagerProbe() and
virSecuritySELinuxDriverProbe()) where callbacks are defined to
return an integer. This is an undefined behavior because integer
has strictly bigger space of possible values than the enum.

Defined those aforementioned callbacks so that they return the
correct enum instead of int.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/security/security_apparmor.c | 2 +-
 src/security/security_selinux.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index c1dc859751..27184aef7f 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -315,7 +315,7 @@ AppArmorSetSecurityHostLabel(virSCSIVHostDevice *dev G_GNUC_UNUSED,
 }
 
 /* Called on libvirtd startup to see if AppArmor is available */
-static int
+static virSecurityDriverStatus
 AppArmorSecurityManagerProbe(const char *virtDriver G_GNUC_UNUSED)
 {
     g_autofree char *template_qemu = NULL;
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index aaec34ff8b..e29f627bc2 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1039,7 +1039,7 @@ virSecuritySELinuxReserveLabel(virSecurityManager *mgr,
 }
 
 
-static int
+static virSecurityDriverStatus
 virSecuritySELinuxDriverProbe(const char *virtDriver)
 {
     if (is_selinux_enabled() <= 0)
-- 
2.43.2
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [PATCH 04/13] security: Fix return types of .probe callbacks
Posted by Daniel P. Berrangé 1 year, 9 months ago
On Mon, May 06, 2024 at 10:43:01AM +0200, Michal Privoznik wrote:
> The .probe member of virSecurityDriver struct is declared to
> return virSecurityDriverStatus enum. But there are two instances
> (AppArmorSecurityManagerProbe() and
> virSecuritySELinuxDriverProbe()) where callbacks are defined to
> return an integer. This is an undefined behavior because integer
> has strictly bigger space of possible values than the enum.
> 
> Defined those aforementioned callbacks so that they return the
> correct enum instead of int.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/security/security_apparmor.c | 2 +-
>  src/security/security_selinux.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org