Skip to content

Commit

Permalink
Have krb5.init_context() raise an exception on error. (#22)
Browse files Browse the repository at this point in the history
init_context() currently just returns a null pointer if the C routine
fails, which is unlike the norm in this module and I assume is an
oversight. Typically this will fail if there's a syntax error in the
libkrb5 configuration (/etc/krb5.conf, or whatever is read). A program
I wrote segfaulted in this situation, because I then passed the null
context to other routines. With this change, we get instead:

In [2]: ctx = krb5.init_context()
---------------------------------------------------------------------------
Krb5Error                                 Traceback (most recent call last)
...
Krb5Error: Included profile file could not be read -1429577697
  • Loading branch information
pseudometric authored Nov 16, 2022
1 parent 1e3ca4f commit 2e5284a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/krb5/_context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ cdef class Context:


def init_context() -> Context:
cdef krb5_error_code = 0
context = Context()
krb5_init_context(&context.raw)

err = krb5_init_context(&context.raw)
if err:
raise Krb5Error(context, err)

return context

Expand Down

0 comments on commit 2e5284a

Please # to comment.