diff options
author | Greg Hudson <ghudson@mit.edu> | 2013-04-08 15:32:31 -0400 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2013-04-08 15:32:31 -0400 |
commit | 31124ffb81e8c0935403a9fdc169dead5ecaa777 (patch) | |
tree | 837d49e7ef8de324f8ad288ab3231ca2acdcdbd7 /src/lib/krb5/krb/unparse.c | |
parent | caaf72893a5be61822763eb471f4d573992479ed (diff) | |
download | krb5-31124ffb81e8c0935403a9fdc169dead5ecaa777.tar.gz krb5-31124ffb81e8c0935403a9fdc169dead5ecaa777.tar.xz krb5-31124ffb81e8c0935403a9fdc169dead5ecaa777.zip |
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.
Diffstat (limited to 'src/lib/krb5/krb/unparse.c')
-rw-r--r-- | src/lib/krb5/krb/unparse.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/lib/krb5/krb/unparse.c b/src/lib/krb5/krb/unparse.c index 779121a86..5bb64d00a 100644 --- a/src/lib/krb5/krb/unparse.c +++ b/src/lib/krb5/krb/unparse.c @@ -90,7 +90,8 @@ copy_component_quoting(char *dest, const krb5_data *src, int flags) int length = src->length; if (flags & KRB5_PRINCIPAL_UNPARSE_DISPLAY) { - memcpy(dest, src->data, src->length); + if (src->length > 0) + memcpy(dest, src->data, src->length); return src->length; } |