From 91154d55980db0395329cda7f98bd3770755a0c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Tue, 12 Feb 2008 11:47:33 +0000 Subject: [PATCH] add xn-- and handle error git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22591 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/wind/punycode.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/wind/punycode.c b/lib/wind/punycode.c index 73a5086a4..ccd79beb8 100644 --- a/lib/wind/punycode.c +++ b/lib/wind/punycode.c @@ -34,6 +34,7 @@ #ifdef HAVE_CONFIG_H #include #endif +#include #include "windlocl.h" RCSID("$Id$"); @@ -70,9 +71,24 @@ adapt(unsigned delta, unsigned numpoints, int first) return k + (((base - t_min + 1) * delta) / (delta + skew)); } +/** + * Convert an UCS4 string to a puny-coded DNS label string suitable + * when combined with delimiters and other labels for DNS lookup. + * + * @param in an UCS4 string to convert + * @param in_len the length of in. + * @param out the resulting puny-coded string. + * @param out_len before processing out_len should be the length of + * the out variable, after processing it will be the length of the out + * string. + * + * @return returns 0 on success, an wind error code otherwise + * @ingroup wind + */ + int -wind_punycode_toascii(const uint32_t *in, size_t in_len, - char *out, size_t *out_len) +wind_punycode_label_toascii(const uint32_t *in, size_t in_len, + char *out, size_t *out_len) { unsigned n = initial_n; unsigned delta = 0; @@ -82,7 +98,6 @@ wind_punycode_toascii(const uint32_t *in, size_t in_len, unsigned i; unsigned o = 0; unsigned m; - int ret = 0; for (i = 0; i < in_len; ++i) { if (in[i] < 0x80) { @@ -99,7 +114,12 @@ wind_punycode_toascii(const uint32_t *in, size_t in_len, out[o++] = 0x2D; } while (h < in_len) { - ret = 1; + if (o + 4 >= *out_len) + return WIND_ERR_OVERRUN; + memmove(out + 4, out, o); + memcpy(out, "xn--", 4); + o += 4; + m = (unsigned)-1; for (i = 0; i < in_len; ++i) if(in[i] < m && in[i] >= n) @@ -142,5 +162,5 @@ wind_punycode_toascii(const uint32_t *in, size_t in_len, } *out_len = o; - return ret; + return 0; }