diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-12-04 13:12:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-12-04 13:12:42 +0000 |
commit | 9e249590e5d750c70ec61d1100c70d325374dbd8 (patch) | |
tree | 4de3fcf435f9f4f38d1e281c4fbe1ac40c74ab8e /src/dns | |
parent | c03182d1e7b55b18d9a66cf890effb11c5dc7a45 (diff) | |
download | gnunet-9e249590e5d750c70ec61d1100c70d325374dbd8.tar.gz gnunet-9e249590e5d750c70ec61d1100c70d325374dbd8.zip |
-ensure labels are less than 64 chars, add test for full DNS names
Diffstat (limited to 'src/dns')
-rw-r--r-- | src/dns/dnsparser.c | 44 | ||||
-rw-r--r-- | src/dns/dnsparser.h | 2 |
2 files changed, 44 insertions, 2 deletions
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c index 8578e7572..cea9cd137 100644 --- a/src/dns/dnsparser.c +++ b/src/dns/dnsparser.c | |||
@@ -46,16 +46,58 @@ int | |||
46 | GNUNET_DNSPARSER_check_label (const char *label) | 46 | GNUNET_DNSPARSER_check_label (const char *label) |
47 | { | 47 | { |
48 | char *output; | 48 | char *output; |
49 | size_t slen; | ||
49 | 50 | ||
51 | if (NULL != strchr (label, ".")) | ||
52 | return GNUNET_SYSERR; /* not a label! Did you mean GNUNET_DNSPARSER_check_name? */ | ||
50 | if (IDNA_SUCCESS != | 53 | if (IDNA_SUCCESS != |
51 | idna_to_ascii_8z (label, &output, IDNA_USE_STD3_ASCII_RULES)) | 54 | idna_to_ascii_8z (label, &output, IDNA_USE_STD3_ASCII_RULES)) |
52 | return GNUNET_SYSERR; | 55 | return GNUNET_SYSERR; |
56 | slen = strlen (output); | ||
53 | #if WINDOWS | 57 | #if WINDOWS |
54 | idn_free (output); | 58 | idn_free (output); |
55 | #else | 59 | #else |
56 | free (output); | 60 | free (output); |
57 | #endif | 61 | #endif |
58 | return GNUNET_OK; | 62 | return (slen > 63) ? GNUNET_SYSERR : GNUNET_OK; |
63 | } | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Check if a label in UTF-8 format can be coded into valid IDNA. | ||
68 | * This can fail if the ASCII-conversion becomes longer than 253 characters. | ||
69 | * | ||
70 | * @param name name to check (UTF-8 string) | ||
71 | * @return GNUNET_OK if the label can be converted to IDNA, | ||
72 | * GNUNET_SYSERR if the label is not valid for DNS names | ||
73 | */ | ||
74 | int | ||
75 | GNUNET_DNSPARSER_check_name (const char *label) | ||
76 | { | ||
77 | char *ldup; | ||
78 | char *output; | ||
79 | size_t slen; | ||
80 | char *tok; | ||
81 | |||
82 | ldup = GNUNET_strdup (label); | ||
83 | for (tok = strtok (ldup, "."); NULL != tok; tok = strtok (NULL, ".")) | ||
84 | if (GNUNET_OK != | ||
85 | GNUNET_DNSPARSER_check_label (tok)) | ||
86 | { | ||
87 | GNUNET_free (ldup); | ||
88 | return GNUNET_SYSERR; | ||
89 | } | ||
90 | GNUNET_free (ldup); | ||
91 | if (IDNA_SUCCESS != | ||
92 | idna_to_ascii_8z (label, &output, IDNA_USE_STD3_ASCII_RULES)) | ||
93 | return GNUNET_SYSERR; | ||
94 | slen = strlen (output); | ||
95 | #if WINDOWS | ||
96 | idn_free (output); | ||
97 | #else | ||
98 | free (output); | ||
99 | #endif | ||
100 | return (slen > 253) ? GNUNET_SYSERR : GNUNET_OK; | ||
59 | } | 101 | } |
60 | 102 | ||
61 | 103 | ||
diff --git a/src/dns/dnsparser.h b/src/dns/dnsparser.h index e3ab622c7..9d2880a69 100644 --- a/src/dns/dnsparser.h +++ b/src/dns/dnsparser.h | |||
@@ -187,7 +187,7 @@ struct vpn_data | |||
187 | */ | 187 | */ |
188 | struct GNUNET_HashCode peer; | 188 | struct GNUNET_HashCode peer; |
189 | 189 | ||
190 | /* followed by the servicename */ | 190 | /* followed by the servicename / identifier / password (0-terminated) */ |
191 | }; | 191 | }; |
192 | 192 | ||
193 | GNUNET_NETWORK_STRUCT_END | 193 | GNUNET_NETWORK_STRUCT_END |