Assigning 64-bit errcode_t to 32-bit krb5_error_code
(sorry for this being longish)
in krb5 sources error codes are mostly represented as two types:
typedef krb5_int32 krb5_error_code
typedef long errcode_t;
At some places values of the latter are assigned to variables of the
former. It would make sense, if values assigned to errcode_t were
guaranteed to fit in 32-bit integer (after all, errcode_t is 32-bit on
32-bit architecture). In that case, the discrepancy would be merely a
code purity issue.
But are there guaranties, that no function will ever return an error
code that would overflow 32-bit integer?
I identified two areas in the code, where errcode_t value is assigned to
1) Extended error hook functions
Most of the hook functions call krb5_get_error_message, internally
casting errcode_t to krb5_error_code and then back
And with profile plug-ins, the error code can origin in the plug-in,
depriving the code from the control of the specific values. Unless there
is some convention for the errcode_t values, the plug-in can return a
64-bit value, where the lowest 4 bytes collide with some defined
krb5_error_code value. In that case the 'lost of precision' in the
assignment results in a wrong interpretation of the error code.
Is there anything (besides common sense) forbidding errcode_t values
overflowing 32-bit integer?