heimdal-utf8-fixes-02.patches.txt

"Stefan (metze) Metzmacher" <[email protected]>
Newsgroups gmane.comp.encryption.kerberos.heimdal.general
Message-ID <[email protected]>
Hi Love,

here're some utf8 related fixes.

metze
heimdal-utf8-fixes-02.patches.txt (text/plain, 5.6 KB)
From a3764b498d867c0965e30d4c16423992eede1bb6 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <[email protected]>
Date: Tue, 15 Nov 2011 15:57:10 +0100
Subject: [PATCH 1/4] lib/wind: fix wind_ucs4utf8() and wind_ucs2utf8()

Pair-Programmed-With: Arvid Requate <[email protected]>

metze
---
 lib/wind/utf8.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/wind/utf8.c b/lib/wind/utf8.c
index 6907b3c..fce6def 100644
--- a/lib/wind/utf8.c
+++ b/lib/wind/utf8.c
@@ -204,13 +204,13 @@ wind_ucs4utf8(const uint32_t *in, size_t in_len, char *out, size_t *out_len)
 	    switch(len) {
 	    case 4:
 		out[3] = (ch | 0x80) & 0xbf;
-		ch = ch << 6;
+		ch = ch >> 6;
 	    case 3:
 		out[2] = (ch | 0x80) & 0xbf;
-		ch = ch << 6;
+		ch = ch >> 6;
 	    case 2:
 		out[1] = (ch | 0x80) & 0xbf;
-		ch = ch << 6;
+		ch = ch >> 6;
 	    case 1:
 		out[0] = ch | first_char[len - 1];
 	    }
@@ -479,10 +479,10 @@ wind_ucs2utf8(const uint16_t *in, size_t in_len, char *out, size_t *out_len)
 	    switch(len) {
 	    case 3:
 		out[2] = (ch | 0x80) & 0xbf;
-		ch = ch << 6;
+		ch = ch >> 6;
 	    case 2:
 		out[1] = (ch | 0x80) & 0xbf;
-		ch = ch << 6;
+		ch = ch >> 6;
 	    case 1:
 		out[0] = ch | first_char[len - 1];
 	    }
-- 
1.7.4.1


From 191219dd5cd201094c0e4ff2a7b5e6feb050b5bb Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <[email protected]>
Date: Tue, 15 Nov 2011 15:57:40 +0100
Subject: [PATCH 2/4] lib/winbd: fix wind_ucs2write with WIND_RW_LE

Pair-Programmed-With: Arvid Requate <[email protected]>

metze
---
 lib/wind/utf8.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/wind/utf8.c b/lib/wind/utf8.c
index fce6def..e1a1eb7 100644
--- a/lib/wind/utf8.c
+++ b/lib/wind/utf8.c
@@ -346,8 +346,8 @@ wind_ucs2write(const uint16_t *in, size_t in_len, unsigned int *flags,
 	    return WIND_ERR_OVERRUN;
 
 	if ((*flags) & WIND_RW_LE) {
-	    p[0] = (bom >> 8) & 0xff;
-	    p[1] = (bom     ) & 0xff;
+	    p[0] = (bom     ) & 0xff;
+	    p[1] = (bom >> 8) & 0xff;
 	} else {
 	    p[1] = (bom     ) & 0xff;
 	    p[0] = (bom >> 8) & 0xff;
@@ -360,8 +360,8 @@ wind_ucs2write(const uint16_t *in, size_t in_len, unsigned int *flags,
 	if (len < 2)
 	    return WIND_ERR_OVERRUN;
 	if ((*flags) & WIND_RW_LE) {
-	    p[0] = (in[0] >> 8) & 0xff;
-	    p[1] = (in[0]     ) & 0xff;
+	    p[0] = (in[0]     ) & 0xff;
+	    p[1] = (in[0] >> 8) & 0xff;
 	} else {
 	    p[1] = (in[0]     ) & 0xff;
 	    p[0] = (in[0] >> 8) & 0xff;
-- 
1.7.4.1


From 4a29cdbd7b3be0760ee6321d25488ffcacce12be Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <[email protected]>
Date: Tue, 15 Nov 2011 14:38:38 +0100
Subject: [PATCH 3/4] lib/wind: export wind_ucs2write()

Pair-Programmed-With: Arvid Requate <[email protected]>

metze
---
 lib/wind/version-script.map |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lib/wind/version-script.map b/lib/wind/version-script.map
index a6ca3ae..6b5abb5 100644
--- a/lib/wind/version-script.map
+++ b/lib/wind/version-script.map
@@ -14,6 +14,7 @@ HEIMDAL_WIND_1.0 {
 		wind_utf8ucs2_length;
 		wind_ucs2utf8_length;
 		wind_ucs2read;
+		wind_ucs2write;
 		# testing
 		_wind_combining_class;
 		_wind_stringprep_testbidi;
-- 
1.7.4.1


From c0e530ef04b6b35602ac399e28015b73abca76d7 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <[email protected]>
Date: Tue, 15 Nov 2011 14:32:35 +0100
Subject: [PATCH 4/4] lib/krb5: add utf8 support to build_logon_name() for the PAC

Pair-Programmed-With: Arvid Requate <[email protected]>

metze
---
 lib/krb5/pac.c |   67 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/lib/krb5/pac.c b/lib/krb5/pac.c
index f4caadd..91f68d5 100644
--- a/lib/krb5/pac.c
+++ b/lib/krb5/pac.c
@@ -706,7 +706,7 @@ build_logon_name(krb5_context context,
     krb5_storage *sp;
     uint64_t t;
     char *s, *s2;
-    size_t i, len;
+    size_t s2_len;
 
     t = unix2nttime(authtime);
 
@@ -726,29 +726,60 @@ build_logon_name(krb5_context context,
     if (ret)
 	goto out;
 
-    len = strlen(s);
+    {
+	size_t ucs2_len;
+	uint16_t *ucs2;
+	unsigned int flags;
 
-    CHECK(ret, krb5_store_uint16(sp, len * 2), out);
+	ret = wind_utf8ucs2_length(s, &ucs2_len);
+	if (ret) {
+	    free(s);
+	    krb5_set_error_message(context, ret, "Failed to count length of UTF-8 string");
+	    return ret;
+	}
 
-#if 1 /* cheat for now */
-    s2 = malloc(len * 2);
-    if (s2 == NULL) {
-	ret = krb5_enomem(context);
+	ucs2 = malloc(sizeof(ucs2[0]) * ucs2_len);
+	if (ucs2 == NULL) {
+	    free(s);
+	    return krb5_enomem(context);
+	}
+
+	ret = wind_utf8ucs2(s, ucs2, &ucs2_len);
 	free(s);
-	goto out;
-    }
-    for (i = 0; i < len; i++) {
-	s2[i * 2] = s[i];
-	s2[i * 2 + 1] = 0;
+	if (ret) {
+	    free(ucs2);
+	    krb5_set_error_message(context, ret, "Failed to convert string to UCS-2");
+	    return ret;
+	}
+
+	s2_len = (ucs2_len + 1) * 2;
+	s2 = malloc(s2_len);
+	if (ucs2 == NULL) {
+	    free(ucs2);
+	    return krb5_enomem(context);
+	}
+
+	flags = WIND_RW_LE;
+	ret = wind_ucs2write(ucs2, ucs2_len,
+			     &flags, s2, &s2_len);
+	free(ucs2);
+	if (ret) {
+	    free(s2);
+	    krb5_set_error_message(context, ret, "Failed to write to UCS-2 buffer");
+	    return ret;
+	}
+
+	/*
+	 * we do not want zero termination
+	 */
+	s2_len = ucs2_len * 2;
     }
-    free(s);
-#else
-    /* write libwind code here */
-#endif
 
-    ret = krb5_storage_write(sp, s2, len * 2);
+    CHECK(ret, krb5_store_uint16(sp, s2_len), out);
+
+    ret = krb5_storage_write(sp, s2, s2_len);
     free(s2);
-    if (ret != (int)(len * 2)) {
+    if (ret != (int)s2_len) {
 	ret = krb5_enomem(context);
 	goto out;
     }
-- 
1.7.4.1
signature.asc (application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7DaE8ACgkQm70gjA5TCD/3bQCeJJgs8tgBJJwHQ828zYHperM4
9l0AoIcjd4nPIqGYlzgiZlSmx7J6f9qk
=kGf7
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.