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/namestore | |
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/namestore')
-rw-r--r-- | src/namestore/namestore_common.c | 101 |
1 files changed, 63 insertions, 38 deletions
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c index f81a287c3..632ca756a 100644 --- a/src/namestore/namestore_common.c +++ b/src/namestore/namestore_common.c | |||
@@ -348,18 +348,19 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type, | |||
348 | size_t data_size) | 348 | size_t data_size) |
349 | { | 349 | { |
350 | uint16_t mx_pref; | 350 | uint16_t mx_pref; |
351 | struct soa_data *soa; | 351 | const struct soa_data *soa; |
352 | struct vpn_data *vpn; | 352 | const struct vpn_data *vpn; |
353 | struct srv_data *srv; | 353 | const struct srv_data *srv; |
354 | struct tlsa_data *tlsa; | 354 | const struct tlsa_data *tlsa; |
355 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded enc; | 355 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded enc; |
356 | struct GNUNET_CRYPTO_HashAsciiEncoded s_peer; | 356 | struct GNUNET_CRYPTO_HashAsciiEncoded s_peer; |
357 | const char *cdata; | ||
357 | char* vpn_str; | 358 | char* vpn_str; |
358 | char* srv_str; | 359 | char* srv_str; |
359 | char* tlsa_str; | 360 | char* tlsa_str; |
360 | char* result; | 361 | char* result; |
361 | char* soa_rname; | 362 | const char* soa_rname; |
362 | char* soa_mname; | 363 | const char* soa_mname; |
363 | char tmp[INET6_ADDRSTRLEN]; | 364 | char tmp[INET6_ADDRSTRLEN]; |
364 | 365 | ||
365 | switch (type) | 366 | switch (type) |
@@ -373,20 +374,32 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type, | |||
373 | return NULL; | 374 | return NULL; |
374 | return GNUNET_strdup (tmp); | 375 | return GNUNET_strdup (tmp); |
375 | case GNUNET_DNSPARSER_TYPE_NS: | 376 | case GNUNET_DNSPARSER_TYPE_NS: |
376 | return GNUNET_strdup (data); | 377 | return GNUNET_strndup (data, data_size); |
377 | case GNUNET_DNSPARSER_TYPE_CNAME: | 378 | case GNUNET_DNSPARSER_TYPE_CNAME: |
378 | return GNUNET_strdup (data); | 379 | return GNUNET_strndup (data, data_size); |
379 | case GNUNET_DNSPARSER_TYPE_SOA: | 380 | case GNUNET_DNSPARSER_TYPE_SOA: |
380 | soa = (struct soa_data*)data; | 381 | if (data_size <= sizeof (struct soa_data)) |
381 | soa_rname = (char*)&soa[1]; | 382 | return NULL; |
382 | soa_mname = (char*)&soa[1]+strlen(soa_rname)+1; | 383 | soa = data; |
383 | if (0 == GNUNET_asprintf(&result, "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu", | 384 | soa_rname = (const char*) &soa[1]; |
384 | soa_rname, soa_mname, | 385 | soa_mname = memchr (soa_rname, 0, data_size - sizeof (struct soa_data) - 1); |
385 | ntohl (soa->serial), ntohl (soa->refresh), | 386 | if (NULL == soa_mname) |
386 | ntohl (soa->retry), ntohl (soa->expire), ntohl (soa->minimum))) | 387 | return NULL; |
388 | soa_mname++; | ||
389 | if (NULL == memchr (soa_mname, 0, | ||
390 | data_size - (sizeof (struct soa_data) + strlen (soa_rname) + 1))) | ||
391 | return NULL; | ||
392 | if (0 == GNUNET_asprintf (&result, | ||
393 | "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu", | ||
394 | soa_rname, soa_mname, | ||
395 | ntohl (soa->serial), | ||
396 | ntohl (soa->refresh), | ||
397 | ntohl (soa->retry), | ||
398 | ntohl (soa->expire), | ||
399 | ntohl (soa->minimum))) | ||
387 | { | 400 | { |
388 | GNUNET_free (result); | 401 | GNUNET_free (result); |
389 | return NULL; | 402 | return NULL; |
390 | } | 403 | } |
391 | return result; | 404 | return result; |
392 | case GNUNET_DNSPARSER_TYPE_PTR: | 405 | case GNUNET_DNSPARSER_TYPE_PTR: |
@@ -420,42 +433,54 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type, | |||
420 | case GNUNET_NAMESTORE_TYPE_LEHO: | 433 | case GNUNET_NAMESTORE_TYPE_LEHO: |
421 | return GNUNET_strndup (data, data_size); | 434 | return GNUNET_strndup (data, data_size); |
422 | case GNUNET_NAMESTORE_TYPE_VPN: | 435 | case GNUNET_NAMESTORE_TYPE_VPN: |
423 | vpn = (struct vpn_data*)data; | 436 | cdata = data; |
424 | 437 | if ( (data_size <= sizeof (struct vpn_data)) || | |
438 | ('\0' != cdata[data_size - 1]) ) | ||
439 | return NULL; /* malformed */ | ||
440 | vpn = data; | ||
425 | GNUNET_CRYPTO_hash_to_enc (&vpn->peer, &s_peer); | 441 | GNUNET_CRYPTO_hash_to_enc (&vpn->peer, &s_peer); |
426 | if (0 == GNUNET_asprintf (&vpn_str, "%hu %s %s", | 442 | if (0 == GNUNET_asprintf (&vpn_str, "%hu %s %s", |
427 | vpn->proto, | 443 | vpn->proto, |
428 | (char*)&s_peer, | 444 | (const char*) &s_peer, |
429 | (char*)&vpn[1])) | 445 | (const char*) &vpn[1])) |
430 | { | 446 | { |
431 | GNUNET_free (vpn_str); | 447 | GNUNET_free (vpn_str); |
432 | return NULL; | 448 | return NULL; |
433 | } | 449 | } |
434 | return vpn_str; | 450 | return vpn_str; |
435 | case GNUNET_DNSPARSER_TYPE_SRV: | 451 | case GNUNET_DNSPARSER_TYPE_SRV: |
436 | srv = (struct srv_data*)data; | 452 | cdata = data; |
437 | 453 | if ( (data_size <= sizeof (struct srv_data)) || | |
438 | if (0 == GNUNET_asprintf (&srv_str, "%d %d %d %s", | 454 | ('\0' != cdata[data_size - 1]) ) |
439 | ntohs (srv->prio), | 455 | return NULL; /* malformed */ |
440 | ntohs (srv->weight), | 456 | srv = data; |
441 | ntohs (srv->port), | 457 | |
442 | (char*)&srv[1])) | 458 | if (0 == GNUNET_asprintf (&srv_str, |
459 | "%d %d %d %s", | ||
460 | ntohs (srv->prio), | ||
461 | ntohs (srv->weight), | ||
462 | ntohs (srv->port), | ||
463 | (const char *)&srv[1])) | ||
443 | { | 464 | { |
444 | GNUNET_free (srv_str); | 465 | GNUNET_free (srv_str); |
445 | return NULL; | 466 | return NULL; |
446 | } | 467 | } |
447 | return srv_str; | 468 | return srv_str; |
448 | case GNUNET_DNSPARSER_TYPE_TLSA: | 469 | case GNUNET_DNSPARSER_TYPE_TLSA: |
449 | tlsa = (struct tlsa_data*)data; | 470 | cdata = data; |
450 | 471 | if ( (data_size <= sizeof (struct tlsa_data)) || | |
451 | if (0 == GNUNET_asprintf (&tlsa_str, "%c %c %c %s", | 472 | ('\0' != cdata[data_size - 1]) ) |
452 | tlsa->usage, | 473 | return NULL; /* malformed */ |
453 | tlsa->selector, | 474 | tlsa = data; |
454 | tlsa->matching_type, | 475 | if (0 == GNUNET_asprintf (&tlsa_str, |
455 | tlsa[1])) | 476 | "%c %c %c %s", |
477 | tlsa->usage, | ||
478 | tlsa->selector, | ||
479 | tlsa->matching_type, | ||
480 | (const char *) &tlsa[1])) | ||
456 | { | 481 | { |
457 | GNUNET_free (tlsa_str); | 482 | GNUNET_free (tlsa_str); |
458 | return NULL; | 483 | return NULL; |
459 | } | 484 | } |
460 | return tlsa_str; | 485 | return tlsa_str; |
461 | default: | 486 | default: |