summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/krb/conv_princ.c
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2013-04-08 15:32:31 -0400
committerGreg Hudson <ghudson@mit.edu>2013-04-08 15:32:31 -0400
commit31124ffb81e8c0935403a9fdc169dead5ecaa777 (patch)
tree837d49e7ef8de324f8ad288ab3231ca2acdcdbd7 /src/lib/krb5/krb/conv_princ.c
parentcaaf72893a5be61822763eb471f4d573992479ed (diff)
downloadkrb5-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/conv_princ.c')
-rw-r--r--src/lib/krb5/krb/conv_princ.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/lib/krb5/krb/conv_princ.c b/src/lib/krb5/krb/conv_princ.c
index 04d4b6514a..c33c67dda5 100644
--- a/src/lib/krb5/krb/conv_princ.c
+++ b/src/lib/krb5/krb/conv_princ.c
@@ -194,7 +194,8 @@ krb5_524_conv_principal(krb5_context context, krb5_const_principal princ,
compo = &princ->data[1];
if (compo->length >= INST_SZ - 1)
return KRB5_INVALID_PRINCIPAL;
- memcpy(inst, compo->data, compo->length);
+ if (compo->length > 0)
+ memcpy(inst, compo->data, compo->length);
inst[compo->length] = '\0';
}
/* fall through */
@@ -204,7 +205,8 @@ krb5_524_conv_principal(krb5_context context, krb5_const_principal princ,
compo = &princ->data[0];
if (compo->length >= ANAME_SZ)
return KRB5_INVALID_PRINCIPAL;
- memcpy(name, compo->data, compo->length);
+ if (compo->length > 0)
+ memcpy(name, compo->data, compo->length);
name[compo->length] = '\0';
}
break;