Re: [PATCH] seobject: Handle python error returns correctly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/30/2016 10:47 AM, Kyle Walker wrote:
> After 9406ace8 ("libsemanage: throw exceptions in python rather than
> return NULL"), calls to libsemanage functions return Python exceptions
> instead of returning negative error return codes. For systems that did not
> have the applicable headers installed prior to build, the difference was
> not seen. Following commit 9792099f ("Properly build the swig exception
> file even if the headers are missing"), that issue has been resolved and
> the underlying semanage_fcontext_query_local and semanage_fcontext_query
> calls now result in an OSError return. This results in the following error
> when attempting to modify a fcontext defined in the systems base policy.
> 
>     libsemanage.dbase_llist_query: could not query record value (No such file or directory).
>     OSError: No such file or directory
> 
> To resolve the error, handle the OSError exception, but retain the
> previous query operation.
> 
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1398427

Hmm...even after this patch, we still get the error message from
dbase_llist_query.  Wondering if we should drop that or if that would
hide anything useful for other errors.  Doesn't seem overly useful at
present.

> 
> Signed-off-by: Kyle Walker <kwalker@xxxxxxxxxx>
> ---
>  python/semanage/seobject.py | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index bb049c0..5f5fdec 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -1953,10 +1953,12 @@ class fcontextRecords(semanageRecords):
>              if not exists:
>                  raise ValueError(_("File context for %s is not defined") % target)
>  
> -        (rc, fcontext) = semanage_fcontext_query_local(self.sh, k)
> -        if rc < 0:
> -            (rc, fcontext) = semanage_fcontext_query(self.sh, k)
> -            if rc < 0:
> +        try:
> +            (rc, fcontext) = semanage_fcontext_query_local(self.sh, k)
> +        except OSError:
> +            try:
> +                (rc, fcontext) = semanage_fcontext_query(self.sh, k)
> +            except OSError:
>                  raise ValueError(_("Could not query file context for %s") % target)
>  
>          if setype != "<<none>>":
> 

_______________________________________________
Selinux mailing list
Selinux@xxxxxxxxxxxxx
To unsubscribe, send email to Selinux-leave@xxxxxxxxxxxxx.
To get help, send an email containing "help" to Selinux-request@xxxxxxxxxxxxx.



[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux