]> git.ipfire.org Git - thirdparty/krb5.git/commit
Avoid passing null pointers to memcpy/memcmp
authorGreg Hudson <ghudson@mit.edu>
Mon, 8 Apr 2013 19:32:31 +0000 (15:32 -0400)
committerGreg Hudson <ghudson@mit.edu>
Mon, 8 Apr 2013 19:32:31 +0000 (15:32 -0400)
commit31124ffb81e8c0935403a9fdc169dead5ecaa777
tree837d49e7ef8de324f8ad288ab3231ca2acdcdbd7
parentcaaf72893a5be61822763eb471f4d573992479ed
Avoid passing null pointers to memcpy/memcmp

By a strict reading of the C standard, memcpy and memcmp have
undefined behavior if their pointer arguments aren't valid object
pointers, even if the length argument is 0.  Compilers are becoming
more aggressive about breaking code with undefined behavior, so we
should try to avoid it when possible.

In a krb5_data object, we frequently use NULL as the data value when
the length is 0.  Accordingly, we should avoid copying from or
comparing the data field of a length-0 krb5_data object.  Add checks
to our wrapper functions (like data_eq and k5_memdup) and to code
which works with possibly-empty krb5_data objects.  In a few places,
use wrapper functions to simplify the code rather than adding checks.
21 files changed:
src/include/k5-int.h
src/kdc/kdc_transit.c
src/kdc/kdc_util.c
src/lib/crypto/krb/encrypt.c
src/lib/crypto/krb/s2k_des.c
src/lib/crypto/krb/s2k_pbkdf2.c
src/lib/gssapi/krb5/iakerb.c
src/lib/krb5/ccache/ccfns.c
src/lib/krb5/ccache/ccselect_k5identity.c
src/lib/krb5/krb/authdata.c
src/lib/krb5/krb/chk_trans.c
src/lib/krb5/krb/conv_princ.c
src/lib/krb5/krb/get_in_tkt.c
src/lib/krb5/krb/pr_to_salt.c
src/lib/krb5/krb/princ_comp.c
src/lib/krb5/krb/s4u_creds.c
src/lib/krb5/krb/unparse.c
src/lib/krb5/krb/walk_rtree.c
src/plugins/preauth/securid_sam2/securid2.c
src/util/support/json.c
src/util/support/k5buf.c