authz: Add missing NULL checks
cover authz: Add missing NULL checks
While trying to write a QAPI schema for user creatable object types, I have to figure out whether properties are mandatory or options.
Turns out that some authz object types have properties that should be mandatory because the code assumes they are non-NULL, but we never check that they are actually given.
Kevin Wolf (2):
authz-pam: Check that 'service' property is set
authz-simple: Check that 'identity' property is set
authz/pamacct.c | 6 ++++++ authz/simple.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+)
Signature · 1 line
2.28.0
PATCH 1/2 authz-pam: Check that 'service' property is set
If the 'service' property is not set, we'll call pam_start() with a NULL pointer for the service name. This fails and leaves a message like this in the syslog:
qemu-storage-daemon[294015]: PAM pam_start: invalid argument: service == NULL
Make specifying the property mandatory and catch the error already during the creation of the object.
--- authz/pamacct.c | 6 ++++++ 1 file changed, 6 insertions(+)
authz/pamacct.c +6 -0
@@ -84,6 +84,12 @@ qauthz_pam_prop_get_service(Object *obj,static void qauthz_pam_complete (UserCreatable *uc,Error **errp) { +QAuthZPAM *pauthz =QAUTHZ_PAM (uc); + +if (!pauthz->service) { +error_setg (errp,"The 'service' property must be set" ); +return ; + } }
Signature · 1 line
2.28.0
PATCH 2/2 authz-simple: Check that 'identity' property is set
In reply to Kevin WolfIf the 'identify' property is not set, we'll pass a NULL pointer to g_str_equal() and crash. Catch the error condition during the creation of the object.
--- authz/simple.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
authz/simple.c +14 -0
@@ -65,11 +65,25 @@ qauthz_simple_finalize(Object *obj) } +static void +qauthz_simple_complete (UserCreatable *uc,Error **errp) +{ +QAuthZSimple *sauthz =QAUTHZ_SIMPLE (uc); + +if (!sauthz->identity) { +error_setg (errp,"The 'identity' property must be set" ); +return ; + } +} + +static void qauthz_simple_class_init (ObjectClass *oc,void *data) {QAuthZClass *authz =QAUTHZ_CLASS (oc); +UserCreatableClass *ucc =USER_CREATABLE_CLASS (oc); + ucc->complete = qauthz_simple_complete; authz->is_allowed = qauthz_simple_is_allowed; object_class_property_add_str(oc, "identity",
Signature · 1 line
2.28.0
Re: [PATCH for-5.2? 1/2] authz-pam: Check that 'service' property is set
In reply to Kevin WolfQuoted 6 lines · Kevin Wolf
If the 'service' property is not set, we'll call
pam_start()with a NULL pointer for the service name. This fails and leaves a message like this in the syslog:qemu-storage-daemon[294015]: PAM
pam_start: invalid argument: service == NULL
Quoted 7 lines
Make specifying the property mandatory and catch the error already during the creation of the object.
Signed-off-by Kevin Wolf <[email protected]>--- authz/pamacct.c | 6 ++++++ 1 file changed, 6 insertions(+)
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Re: [PATCH for-5.2? 2/2] authz-simple: Check that 'identity' property is set
In reply to Kevin WolfQuoted 8 lines · Kevin Wolf
If the 'identify' property is not set, we'll pass a NULL pointer to
g_str_equal()and crash. Catch the error condition during the creation of the object.Signed-off-by Kevin Wolf <[email protected]>--- authz/simple.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Quoted 6 lines · Kevin Wolf
While trying to write a QAPI schema for user creatable object types, I have to figure out whether properties are mandatory or options.
Turns out that some authz object types have properties that should be mandatory because the code assumes they are non-NULL, but we never check that they are actually given.
Hmm, avoiding manual code to check for mandatory options will be a nice plus point of using QAPI
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Re: [PATCH for-5.2? 1/2] authz-pam: Check that 'service' property is set
In reply to Kevin WolfQuoted 6 lines · Kevin Wolf
If the 'service' property is not set, we'll call
pam_start()with a NULL pointer for the service name. This fails and leaves a message like this in the syslog:qemu-storage-daemon[294015]: PAM
pam_start: invalid argument: service == NULL
Quoted 7 lines
Make specifying the property mandatory and catch the error already during the creation of the object.
Signed-off-by Kevin Wolf <[email protected]>--- authz/pamacct.c | 6 ++++++ 1 file changed, 6 insertions(+)
Re: [PATCH for-5.2? 2/2] authz-simple: Check that 'identity' property is set
In reply to Kevin WolfQuoted 8 lines · Kevin Wolf
If the 'identify' property is not set, we'll pass a NULL pointer to
g_str_equal()and crash. Catch the error condition during the creation of the object.Signed-off-by Kevin Wolf <[email protected]>--- authz/simple.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)