aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-07 00:24:59 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-07 00:24:59 +0000
commit222e534eed64a24d843e0ee676579ea9b6264bbc (patch)
tree697ecd3137dbb87428be857fad1134787fc951bc /src/gnsrecord
parent0925fad2014e4910d44bb4d9d9681da4e6962e49 (diff)
downloadgnunet-222e534eed64a24d843e0ee676579ea9b6264bbc.tar.gz
gnunet-222e534eed64a24d843e0ee676579ea9b6264bbc.zip
more tlsa fixes
Diffstat (limited to 'src/gnsrecord')
-rw-r--r--src/gnsrecord/plugin_gnsrecord_dns.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c
index b52dee374..b55d595d4 100644
--- a/src/gnsrecord/plugin_gnsrecord_dns.c
+++ b/src/gnsrecord/plugin_gnsrecord_dns.c
@@ -44,7 +44,6 @@ dns_value_to_string (void *cls,
44 const void *data, 44 const void *data,
45 size_t data_size) 45 size_t data_size)
46{ 46{
47 const char *cdata;
48 char* result; 47 char* result;
49 char tmp[INET6_ADDRSTRLEN]; 48 char tmp[INET6_ADDRSTRLEN];
50 49
@@ -231,23 +230,26 @@ dns_value_to_string (void *cls,
231 case GNUNET_DNSPARSER_TYPE_TLSA: 230 case GNUNET_DNSPARSER_TYPE_TLSA:
232 { 231 {
233 const struct GNUNET_TUN_DnsTlsaRecord *tlsa; 232 const struct GNUNET_TUN_DnsTlsaRecord *tlsa;
234 char* tlsa_str; 233 char *tlsa_str;
234 char *hex;
235 235
236 cdata = data; 236 if (data_size < sizeof (struct GNUNET_TUN_DnsTlsaRecord))
237 if ( (data_size <= sizeof (struct GNUNET_TUN_DnsTlsaRecord)) ||
238 ('\0' != cdata[data_size - 1]) )
239 return NULL; /* malformed */ 237 return NULL; /* malformed */
240 tlsa = data; 238 tlsa = data;
239 hex = GNUNET_DNSPARSER_bin_to_hex (&tlsa[1],
240 data_size - sizeof (struct GNUNET_TUN_DnsTlsaRecord));
241 if (0 == GNUNET_asprintf (&tlsa_str, 241 if (0 == GNUNET_asprintf (&tlsa_str,
242 "%u %u %u %s", 242 "%u %u %u %s",
243 (unsigned int) tlsa->usage, 243 (unsigned int) tlsa->usage,
244 (unsigned int) tlsa->selector, 244 (unsigned int) tlsa->selector,
245 (unsigned int) tlsa->matching_type, 245 (unsigned int) tlsa->matching_type,
246 (const char *) &tlsa[1])) 246 hex))
247 { 247 {
248 GNUNET_free (hex);
248 GNUNET_free (tlsa_str); 249 GNUNET_free (tlsa_str);
249 return NULL; 250 return NULL;
250 } 251 }
252 GNUNET_free (hex);
251 return tlsa_str; 253 return tlsa_str;
252 } 254 }
253 default: 255 default:
@@ -603,23 +605,40 @@ dns_string_to_value (void *cls,
603 unsigned int usage; 605 unsigned int usage;
604 unsigned int selector; 606 unsigned int selector;
605 unsigned int matching_type; 607 unsigned int matching_type;
608 size_t slen = strlen (s) + 1;
609 char hex[slen];
606 610
607 *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (s) - 6;
608 *data = tlsa = GNUNET_malloc (*data_size);
609 if (4 != SSCANF (s, 611 if (4 != SSCANF (s,
610 "%u %u %u %s", 612 "%u %u %u %s",
611 (char*)&tlsa[1])) 613 &usage,
614 &selector,
615 &matching_type,
616 hex))
612 { 617 {
613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 618 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
614 _("Unable to parse TLSA record string `%s'\n"), 619 _("Unable to parse TLSA record string `%s'\n"),
615 s); 620 s);
616 *data_size = 0; 621 *data_size = 0;
617 GNUNET_free (tlsa);
618 return GNUNET_SYSERR; 622 return GNUNET_SYSERR;
619 } 623 }
624
625 *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (hex) / 2;
626 *data = tlsa = GNUNET_malloc (*data_size);
620 tlsa->usage = (uint8_t) usage; 627 tlsa->usage = (uint8_t) usage;
621 tlsa->selector = (uint8_t) selector; 628 tlsa->selector = (uint8_t) selector;
622 tlsa->matching_type = (uint8_t) matching_type; 629 tlsa->matching_type = (uint8_t) matching_type;
630 if (strlen (hex) / 2 !=
631 GNUNET_DNSPARSER_hex_to_bin (hex,
632 &tlsa[1]))
633 {
634 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
635 _("Unable to parse TLSA record string `%s'\n"),
636 s);
637 GNUNET_free (*data);
638 *data = NULL;
639 *data_size = 0;
640 return GNUNET_SYSERR;
641 }
623 return GNUNET_OK; 642 return GNUNET_OK;
624 } 643 }
625 default: 644 default: