From 2e356b660726cc84e7ca6b3dd1ff6473e98e78a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Wed, 11 Apr 2007 11:09:37 +0000 Subject: [PATCH] Allow trailing NULs. We allow this since MIT Kerberos sends an strings in the NEED_PREAUTH case that includes a trailing NUL. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20296 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/asn1/der_get.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/asn1/der_get.c b/lib/asn1/der_get.c index e9280ee39..1f9b5d72d 100644 --- a/lib/asn1/der_get.c +++ b/lib/asn1/der_get.c @@ -135,14 +135,25 @@ int der_get_general_string (const unsigned char *p, size_t len, heim_general_string *str, size_t *size) { + const unsigned char *p1; char *s; + p1 = memchr(p, 0, len); + if (p1 != NULL) { + /* + * Allow trailing NULs. We allow this since MIT Kerberos sends + * an strings in the NEED_PREAUTH case that includes a + * trailing NUL. + */ + len = p1 - p; + while (*p1 == '\0' && p1 - p < len) + p1++; + if (p1 - p != len + 1) + return ASN1_BAD_CHARACTER; + } if (len > len + 1) return ASN1_BAD_LENGTH; - if (memchr(p, 0, len) != NULL) - return ASN1_BAD_CHARACTER; - s = malloc (len + 1); if (s == NULL) return ENOMEM;