aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-10-30 20:52:14 +0000
committerChristian Grothoff <christian@grothoff.org>2012-10-30 20:52:14 +0000
commitc95ddb3eac0292511af734768441444098b90be9 (patch)
tree0f9797ab72aba90fb820aca16ff4078040f6f2bb /src/namestore
parentee1230fff885b67efbae4fd194e7c62c93903ae3 (diff)
downloadgnunet-c95ddb3eac0292511af734768441444098b90be9.tar.gz
gnunet-c95ddb3eac0292511af734768441444098b90be9.zip
-more cleanup and input validation fixes
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/namestore_common.c115
1 files changed, 60 insertions, 55 deletions
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c
index 8c42bad67..47029b73b 100644
--- a/src/namestore/namestore_common.c
+++ b/src/namestore/namestore_common.c
@@ -318,22 +318,6 @@ GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key
318 return sig; 318 return sig;
319} 319}
320 320
321/**
322 * Checks if a name is wellformed
323 *
324 * @param name the name to check
325 * @return GNUNET_OK on success, GNUNET_SYSERR on error
326 */
327int
328GNUNET_NAMESTORE_check_name (const char * name)
329{
330 if (name == NULL)
331 return GNUNET_SYSERR;
332 if (strlen (name) > 63)
333 return GNUNET_SYSERR;
334 return GNUNET_OK;
335}
336
337 321
338/** 322/**
339 * Convert the 'value' of a record to a string. 323 * Convert the 'value' of a record to a string.
@@ -489,11 +473,11 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
489 struct soa_data *soa; 473 struct soa_data *soa;
490 struct vpn_data *vpn; 474 struct vpn_data *vpn;
491 struct tlsa_data *tlsa; 475 struct tlsa_data *tlsa;
492 char result[253]; 476 char result[253 + 1];
493 char soa_rname[63]; 477 char soa_rname[253 + 1];
494 char soa_mname[63]; 478 char soa_mname[253 + 1];
495 char s_peer[104]; 479 char s_peer[103 + 1];
496 char s_serv[253]; 480 char s_serv[253 + 1];
497 uint32_t soa_serial; 481 uint32_t soa_serial;
498 uint32_t soa_refresh; 482 uint32_t soa_refresh;
499 uint32_t soa_retry; 483 uint32_t soa_retry;
@@ -502,15 +486,22 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
502 uint16_t mx_pref; 486 uint16_t mx_pref;
503 uint16_t mx_pref_n; 487 uint16_t mx_pref_n;
504 uint16_t proto; 488 uint16_t proto;
505 int ret;
506 489
507 switch (type) 490 switch (type)
508 { 491 {
509 case 0: 492 case 0:
493 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
494 _("Unsupported record type %d\n"),
495 (int) type);
510 return GNUNET_SYSERR; 496 return GNUNET_SYSERR;
511 case GNUNET_DNSPARSER_TYPE_A: 497 case GNUNET_DNSPARSER_TYPE_A:
512 if (1 != inet_pton (AF_INET, s, &value_a)) 498 if (1 != inet_pton (AF_INET, s, &value_a))
499 {
500 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
501 _("Unable to parse IPv4 address `%s'\n"),
502 s);
513 return GNUNET_SYSERR; 503 return GNUNET_SYSERR;
504 }
514 *data = GNUNET_malloc (sizeof (struct in_addr)); 505 *data = GNUNET_malloc (sizeof (struct in_addr));
515 memcpy (*data, &value_a, sizeof (value_a)); 506 memcpy (*data, &value_a, sizeof (value_a));
516 *data_size = sizeof (value_a); 507 *data_size = sizeof (value_a);
@@ -524,13 +515,16 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
524 *data_size = strlen (s) + 1; 515 *data_size = strlen (s) + 1;
525 return GNUNET_OK; 516 return GNUNET_OK;
526 case GNUNET_DNSPARSER_TYPE_SOA: 517 case GNUNET_DNSPARSER_TYPE_SOA:
527 518 if (7 != SSCANF (s,
528 if (SSCANF(s, "rname=%s mname=%s %u,%u,%u,%u,%u", 519 "rname=%253s mname=%253s %u,%u,%u,%u,%u",
529 soa_rname, soa_mname, 520 soa_rname, soa_mname,
530 &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min) 521 &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min))
531 != 7) 522 {
523 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
524 _("Unable to parse SOA record `%s'\n"),
525 s);
532 return GNUNET_SYSERR; 526 return GNUNET_SYSERR;
533 527 }
534 *data_size = sizeof (struct soa_data)+strlen(soa_rname)+strlen(soa_mname)+2; 528 *data_size = sizeof (struct soa_data)+strlen(soa_rname)+strlen(soa_mname)+2;
535 *data = GNUNET_malloc (*data_size); 529 *data = GNUNET_malloc (*data_size);
536 soa = (struct soa_data*)*data; 530 soa = (struct soa_data*)*data;
@@ -542,14 +536,18 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
542 strcpy((char*)&soa[1], soa_rname); 536 strcpy((char*)&soa[1], soa_rname);
543 strcpy((char*)&soa[1]+strlen(*data)+1, soa_mname); 537 strcpy((char*)&soa[1]+strlen(*data)+1, soa_mname);
544 return GNUNET_OK; 538 return GNUNET_OK;
545
546 case GNUNET_DNSPARSER_TYPE_PTR: 539 case GNUNET_DNSPARSER_TYPE_PTR:
547 *data = GNUNET_strdup (s); 540 *data = GNUNET_strdup (s);
548 *data_size = strlen (s); 541 *data_size = strlen (s);
549 return GNUNET_OK; 542 return GNUNET_OK;
550 case GNUNET_DNSPARSER_TYPE_MX: 543 case GNUNET_DNSPARSER_TYPE_MX:
551 if (SSCANF(s, "%hu,%s", &mx_pref, result) != 2) 544 if (2 != SSCANF(s, "%hu,%253s", &mx_pref, result))
545 {
546 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
547 _("Unable to parse MX record `%s'\n"),
548 s);
552 return GNUNET_SYSERR; 549 return GNUNET_SYSERR;
550 }
553 *data_size = sizeof (uint16_t)+strlen(result)+1; 551 *data_size = sizeof (uint16_t)+strlen(result)+1;
554 *data = GNUNET_malloc (*data_size); 552 *data = GNUNET_malloc (*data_size);
555 mx_pref_n = htons(mx_pref); 553 mx_pref_n = htons(mx_pref);
@@ -562,7 +560,12 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
562 return GNUNET_OK; 560 return GNUNET_OK;
563 case GNUNET_DNSPARSER_TYPE_AAAA: 561 case GNUNET_DNSPARSER_TYPE_AAAA:
564 if (1 != inet_pton (AF_INET6, s, &value_aaaa)) 562 if (1 != inet_pton (AF_INET6, s, &value_aaaa))
565 return GNUNET_SYSERR; 563 {
564 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
565 _("Unable to parse IPv6 address `%s'\n"),
566 s);
567 return GNUNET_SYSERR;
568 }
566 *data = GNUNET_malloc (sizeof (struct in6_addr)); 569 *data = GNUNET_malloc (sizeof (struct in6_addr));
567 *data_size = sizeof (struct in6_addr); 570 *data_size = sizeof (struct in6_addr);
568 memcpy (*data, &value_aaaa, sizeof (value_aaaa)); 571 memcpy (*data, &value_aaaa, sizeof (value_aaaa));
@@ -570,7 +573,12 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
570 case GNUNET_NAMESTORE_TYPE_PKEY: 573 case GNUNET_NAMESTORE_TYPE_PKEY:
571 if (GNUNET_OK != 574 if (GNUNET_OK !=
572 GNUNET_CRYPTO_short_hash_from_string (s, &pkey)) 575 GNUNET_CRYPTO_short_hash_from_string (s, &pkey))
576 {
577 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
578 _("Unable to parse PKEY record `%s'\n"),
579 s);
573 return GNUNET_SYSERR; 580 return GNUNET_SYSERR;
581 }
574 *data = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 582 *data = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
575 memcpy (*data, &pkey, sizeof (pkey)); 583 memcpy (*data, &pkey, sizeof (pkey));
576 *data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); 584 *data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
@@ -584,52 +592,49 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
584 *data_size = strlen (s); 592 *data_size = strlen (s);
585 return GNUNET_OK; 593 return GNUNET_OK;
586 case GNUNET_NAMESTORE_TYPE_VPN: 594 case GNUNET_NAMESTORE_TYPE_VPN:
587 595 if (3 != SSCANF (s,"%hu %103s %253s",
588 ret = SSCANF (s,"%hu %s %s", 596 &proto, s_peer, s_serv))
589 &proto, s_peer, s_serv);
590 if (3 != ret)
591 { 597 {
592 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
593 "Unable to parse VPN record string %s %d\n", s, ret); 599 _("Unable to parse VPN record string `%s'\n"),
600 s);
594 return GNUNET_SYSERR; 601 return GNUNET_SYSERR;
595 } 602 }
596 *data_size = sizeof (struct vpn_data) + strlen (s_serv) + 1; 603 *data_size = sizeof (struct vpn_data) + strlen (s_serv) + 1;
597 *data = GNUNET_malloc (*data_size); 604 *data = vpn = GNUNET_malloc (*data_size);
598 605 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer,
599 vpn = (struct vpn_data*)*data; 606 &vpn->peer))
600
601 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer, &vpn->peer))
602 { 607 {
603 GNUNET_free (*data); 608 GNUNET_free (vpn);
609 *data_size = 0;
604 return GNUNET_SYSERR; 610 return GNUNET_SYSERR;
605 } 611 }
606
607 vpn->proto = htons (proto); 612 vpn->proto = htons (proto);
608 strcpy ((char*)&vpn[1], s_serv); 613 strcpy ((char*)&vpn[1], s_serv);
609 return GNUNET_OK; 614 return GNUNET_OK;
610 case GNUNET_DNSPARSER_TYPE_TLSA: 615 case GNUNET_DNSPARSER_TYPE_TLSA:
611 *data_size = sizeof (struct tlsa_data) + strlen (s) - 6; 616 *data_size = sizeof (struct tlsa_data) + strlen (s) - 6;
612 *data = GNUNET_malloc (*data_size); 617 *data = tlsa = GNUNET_malloc (*data_size);
613 tlsa = (struct tlsa_data*)*data; 618 if (4 != SSCANF (s, "%c %c %c %s",
614 ret = SSCANF (s, "%c %c %c %s", 619 &tlsa->usage,
615 &tlsa->usage, 620 &tlsa->selector,
616 &tlsa->selector, 621 &tlsa->matching_type,
617 &tlsa->matching_type, 622 (char*)&tlsa[1]))
618 (char*)&tlsa[1]);
619
620 if (4 != ret)
621 { 623 {
622 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 624 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
623 "Unable to parse TLSA record string %s\n", s); 625 _("Unable to parse TLSA record string `%s'\n"),
626 s);
624 *data_size = 0; 627 *data_size = 0;
625 GNUNET_free (tlsa); 628 GNUNET_free (tlsa);
626 return GNUNET_SYSERR; 629 return GNUNET_SYSERR;
627 } 630 }
628 return GNUNET_OK; 631 return GNUNET_OK;
629 default: 632 default:
630 GNUNET_break (0); 633 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
634 _("Unsupported record type %d\n"),
635 (int) type);
636 return GNUNET_SYSERR;
631 } 637 }
632 return GNUNET_SYSERR;
633} 638}
634 639
635 640