diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-27 11:59:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-27 11:59:42 +0000 |
commit | 55798b50feda4db5255e991e66ef5c78fadf008a (patch) | |
tree | eb087b4b17ead5002e62acfd00e5e84ac176f544 /src/gns | |
parent | e1d237db3dc7d71e00844da8eb501896cf6d308f (diff) | |
download | gnunet-55798b50feda4db5255e991e66ef5c78fadf008a.tar.gz gnunet-55798b50feda4db5255e991e66ef5c78fadf008a.zip |
-fixing leaks, warnings, adding missing 0-termination checks for IPC messages
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/gns.conf.in | 1 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 153 |
2 files changed, 79 insertions, 75 deletions
diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in index a18446827..916d9862f 100644 --- a/src/gns/gns.conf.in +++ b/src/gns/gns.conf.in | |||
@@ -15,6 +15,7 @@ AUTO_IMPORT_CONFIRMATION_REQ = NO | |||
15 | MAX_PARALLEL_BACKGROUND_QUERIES = 25 | 15 | MAX_PARALLEL_BACKGROUND_QUERIES = 25 |
16 | DEFAULT_LOOKUP_TIMEOUT = 10 | 16 | DEFAULT_LOOKUP_TIMEOUT = 10 |
17 | RECORD_PUT_INTERVAL = 4 h | 17 | RECORD_PUT_INTERVAL = 4 h |
18 | PREFIX = valgrind --leak-check=full --track-origins=yes | ||
18 | 19 | ||
19 | [gns-proxy] | 20 | [gns-proxy] |
20 | PROXY_CACERT = $SERVICEHOME/gns/gnsCAcert.pem | 21 | PROXY_CACERT = $SERVICEHOME/gns/gnsCAcert.pem |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 1a3485982..5ad0bcf76 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -700,6 +700,7 @@ process_private_in_root_zone_lookup (void *cls, | |||
700 | csh); | 700 | csh); |
701 | } | 701 | } |
702 | 702 | ||
703 | |||
703 | /** | 704 | /** |
704 | * Lookup the zone infos and shorten name | 705 | * Lookup the zone infos and shorten name |
705 | * | 706 | * |
@@ -732,36 +733,41 @@ handle_shorten (void *cls, | |||
732 | struct GNUNET_SERVER_Client * client, | 733 | struct GNUNET_SERVER_Client * client, |
733 | const struct GNUNET_MessageHeader * message) | 734 | const struct GNUNET_MessageHeader * message) |
734 | { | 735 | { |
735 | size_t msg_size = 0; | 736 | uint16_t msg_size; |
737 | const struct GNUNET_GNS_ClientShortenMessage *sh_msg; | ||
736 | struct ClientShortenHandle *csh; | 738 | struct ClientShortenHandle *csh; |
739 | const char *utf_in; | ||
737 | char name[MAX_DNS_NAME_LENGTH]; | 740 | char name[MAX_DNS_NAME_LENGTH]; |
738 | char* nameptr = name; | 741 | char* nameptr = name; |
739 | 742 | ||
740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN"); | 743 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN"); |
741 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage)) | 744 | msg_size = ntohs (message->size); |
745 | if (msg_size < sizeof (struct GNUNET_GNS_ClientShortenMessage)) | ||
742 | { | 746 | { |
743 | GNUNET_break (0); | 747 | GNUNET_break (0); |
744 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 748 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
745 | return; | 749 | return; |
746 | } | 750 | } |
747 | 751 | sh_msg = (const struct GNUNET_GNS_ClientShortenMessage *) message; | |
748 | 752 | utf_in = (const char *) &sh_msg[1]; | |
749 | const struct GNUNET_GNS_ClientShortenMessage *sh_msg = | 753 | if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientShortenMessage) - 1]) |
750 | (const struct GNUNET_GNS_ClientShortenMessage *) message; | 754 | { |
751 | 755 | GNUNET_break (0); | |
752 | msg_size = ntohs (message->size); | 756 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
753 | csh = GNUNET_malloc(sizeof (struct ClientShortenHandle)); | 757 | return; |
758 | } | ||
759 | csh = GNUNET_malloc (sizeof (struct ClientShortenHandle)); | ||
754 | csh->client = client; | 760 | csh->client = client; |
755 | csh->unique_id = sh_msg->id; | 761 | csh->unique_id = sh_msg->id; |
756 | 762 | GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); | |
757 | GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); | 763 | GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr); |
758 | |||
759 | GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); | ||
760 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 764 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
761 | "SHORTEN: Converted %s to %s\n", (char*)&sh_msg[1], nameptr); | 765 | "SHORTEN: Converted `%s' to `%s'\n", |
762 | GNUNET_SERVER_notification_context_add (nc, client); | 766 | utf_in, |
763 | 767 | nameptr); | |
764 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) { | 768 | GNUNET_SERVER_notification_context_add (nc, client); |
769 | if (strlen (name) < strlen (GNUNET_GNS_TLD)) | ||
770 | { | ||
765 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 771 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
766 | "SHORTEN: %s is too short\n", name); | 772 | "SHORTEN: %s is too short\n", name); |
767 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); | 773 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); |
@@ -769,39 +775,33 @@ handle_shorten (void *cls, | |||
769 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 775 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
770 | return; | 776 | return; |
771 | } | 777 | } |
772 | 778 | if (strlen (name) > MAX_DNS_NAME_LENGTH) | |
773 | if (strlen (name) > MAX_DNS_NAME_LENGTH) { | 779 | { |
774 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 780 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
775 | "SHORTEN: %s is too long\n", name); | 781 | "SHORTEN: %s is too long\n", name); |
776 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); | 782 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); |
777 | send_shorten_response(csh, name); | 783 | send_shorten_response(csh, name); |
778 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 784 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
779 | return; | 785 | return; |
780 | } | 786 | } |
781 | 787 | if ( (! is_gnunet_tld (name)) && | |
782 | if (!is_gnunet_tld(name) && !is_zkey_tld(name)) | 788 | (! is_zkey_tld (name)) ) |
783 | { | 789 | { |
784 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
785 | "%s is not our domain. Returning\n", name); | 791 | "%s is not our domain. Returning\n", name); |
786 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); | 792 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); |
787 | send_shorten_response(csh, name); | 793 | send_shorten_response (csh, name); |
788 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 794 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
789 | return; | 795 | return; |
790 | } | 796 | } |
791 | |||
792 | csh->shorten_zone = sh_msg->shorten_zone; | 797 | csh->shorten_zone = sh_msg->shorten_zone; |
793 | csh->private_zone = sh_msg->private_zone; | 798 | csh->private_zone = sh_msg->private_zone; |
794 | 799 | strcpy (csh->name, name); | |
795 | strcpy (csh->name, name); | ||
796 | |||
797 | |||
798 | if (1 == ntohl(sh_msg->use_default_zone)) | 800 | if (1 == ntohl(sh_msg->use_default_zone)) |
799 | csh->root_zone = zone_hash; //Default zone | 801 | csh->root_zone = zone_hash; //Default zone |
800 | else | 802 | else |
801 | csh->root_zone = sh_msg->zone; | 803 | csh->root_zone = sh_msg->zone; |
802 | |||
803 | start_shorten_name (csh); | 804 | start_shorten_name (csh); |
804 | |||
805 | GNUNET_STATISTICS_update (statistics, | 805 | GNUNET_STATISTICS_update (statistics, |
806 | "Name shorten attempts", 1, GNUNET_NO); | 806 | "Name shorten attempts", 1, GNUNET_NO); |
807 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 807 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -863,52 +863,53 @@ handle_get_authority (void *cls, | |||
863 | struct GNUNET_SERVER_Client * client, | 863 | struct GNUNET_SERVER_Client * client, |
864 | const struct GNUNET_MessageHeader * message) | 864 | const struct GNUNET_MessageHeader * message) |
865 | { | 865 | { |
866 | size_t msg_size = 0; | 866 | uint16_t msg_size; |
867 | const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg; | ||
867 | struct ClientGetAuthHandle *cah; | 868 | struct ClientGetAuthHandle *cah; |
869 | const char *utf_in; | ||
868 | char name[MAX_DNS_NAME_LENGTH]; | 870 | char name[MAX_DNS_NAME_LENGTH]; |
869 | char* nameptr = name; | 871 | char* nameptr = name; |
870 | 872 | ||
871 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH"); | 873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH"); |
872 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) | 874 | msg_size = ntohs(message->size); |
875 | if (msg_size < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) | ||
873 | { | 876 | { |
874 | GNUNET_break (0); | 877 | GNUNET_break (0); |
875 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 878 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
876 | return; | 879 | return; |
877 | } | 880 | } |
878 | |||
879 | GNUNET_SERVER_notification_context_add (nc, client); | 881 | GNUNET_SERVER_notification_context_add (nc, client); |
880 | 882 | ||
881 | struct GNUNET_GNS_ClientGetAuthMessage *sh_msg = | 883 | sh_msg = (const struct GNUNET_GNS_ClientGetAuthMessage *) message; |
882 | (struct GNUNET_GNS_ClientGetAuthMessage *) message; | 884 | utf_in = (const char *) &sh_msg[1]; |
883 | 885 | if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientGetAuthMessage) - 1]) | |
884 | msg_size = ntohs(message->size); | 886 | { |
885 | GNUNET_STRINGS_utf8_tolower((const char*)&sh_msg[1], &nameptr); | 887 | GNUNET_break (0); |
886 | 888 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | |
887 | 889 | return; | |
890 | } | ||
891 | GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr); | ||
888 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); | 892 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); |
889 | cah->client = client; | 893 | cah->client = client; |
890 | cah->unique_id = sh_msg->id; | 894 | cah->unique_id = sh_msg->id; |
891 | 895 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) | |
892 | if (strlen(name) < strlen(GNUNET_GNS_TLD)) | ||
893 | { | 896 | { |
894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
895 | "GET_AUTH: %s is too short. Returning\n", name); | 898 | "GET_AUTH: `%s' is too short. Returning\n", name); |
896 | cah->name = NULL; | 899 | cah->name = NULL; |
897 | send_get_auth_response(cah, name); | 900 | send_get_auth_response(cah, name); |
898 | return; | 901 | return; |
899 | } | 902 | } |
900 | |||
901 | if (strlen (name) > MAX_DNS_NAME_LENGTH) | 903 | if (strlen (name) > MAX_DNS_NAME_LENGTH) |
902 | { | 904 | { |
903 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 905 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
904 | "GET_AUTH: %s is too long", name); | 906 | "GET_AUTH: `%s' is too long", name); |
905 | cah->name = NULL; | 907 | cah->name = NULL; |
906 | send_get_auth_response(cah, name); | 908 | send_get_auth_response(cah, name); |
907 | return; | 909 | return; |
908 | } | 910 | } |
909 | 911 | if (0 != strcmp (name + strlen (name) - strlen(GNUNET_GNS_TLD), | |
910 | if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD), | 912 | GNUNET_GNS_TLD)) |
911 | GNUNET_GNS_TLD) != 0) | ||
912 | { | 913 | { |
913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
914 | "GET_AUTH: %s is not our domain. Returning\n", name); | 915 | "GET_AUTH: %s is not our domain. Returning\n", name); |
@@ -917,21 +918,20 @@ handle_get_authority (void *cls, | |||
917 | return; | 918 | return; |
918 | } | 919 | } |
919 | 920 | ||
920 | if (strcmp(name, GNUNET_GNS_TLD) == 0) | 921 | if (0 == strcmp(name, GNUNET_GNS_TLD)) |
921 | { | 922 | { |
922 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 923 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
923 | "GET_AUTH: %s is us. Returning\n", name); | 924 | "GET_AUTH: %s is us. Returning\n", name); |
924 | cah->name = NULL; | 925 | cah->name = NULL; |
925 | send_get_auth_response(cah, name); | 926 | send_get_auth_response(cah, name); |
926 | return; | 927 | return; |
927 | } | 928 | } |
928 | 929 | cah->name = GNUNET_malloc(strlen (name) | |
929 | cah->name = GNUNET_malloc(strlen(name) | 930 | - strlen (GNUNET_GNS_TLD) + 1); |
930 | - strlen(GNUNET_GNS_TLD) + 1); | 931 | memset (cah->name, 0, |
931 | memset(cah->name, 0, | 932 | strlen (name) - strlen (GNUNET_GNS_TLD) + 1); |
932 | strlen(name)-strlen(GNUNET_GNS_TLD) + 1); | 933 | memcpy (cah->name, name, |
933 | memcpy(cah->name, name, | 934 | strlen (name) - strlen(GNUNET_GNS_TLD)); |
934 | strlen(name)-strlen(GNUNET_GNS_TLD)); | ||
935 | 935 | ||
936 | /* Start delegation resolution in our namestore */ | 936 | /* Start delegation resolution in our namestore */ |
937 | gns_resolver_get_authority(zone_hash, zone_hash, name, &send_get_auth_response, cah); | 937 | gns_resolver_get_authority(zone_hash, zone_hash, name, &send_get_auth_response, cah); |
@@ -981,7 +981,7 @@ send_lookup_response(void* cls, | |||
981 | GNUNET_free(clh->name); | 981 | GNUNET_free(clh->name); |
982 | 982 | ||
983 | if (NULL != clh->shorten_key) | 983 | if (NULL != clh->shorten_key) |
984 | GNUNET_free(clh->shorten_key); | 984 | GNUNET_CRYPTO_rsa_key_free (clh->shorten_key); |
985 | 985 | ||
986 | GNUNET_free(clh); | 986 | GNUNET_free(clh); |
987 | 987 | ||
@@ -1009,32 +1009,29 @@ handle_lookup(void *cls, | |||
1009 | struct GNUNET_SERVER_Client * client, | 1009 | struct GNUNET_SERVER_Client * client, |
1010 | const struct GNUNET_MessageHeader * message) | 1010 | const struct GNUNET_MessageHeader * message) |
1011 | { | 1011 | { |
1012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); | 1012 | uint16_t msg_size; |
1013 | 1013 | const struct GNUNET_GNS_ClientLookupMessage *sh_msg; | |
1014 | size_t msg_size = 0; | ||
1015 | size_t namelen; | 1014 | size_t namelen; |
1016 | char name[MAX_DNS_NAME_LENGTH]; | 1015 | char name[MAX_DNS_NAME_LENGTH]; |
1017 | struct ClientLookupHandle *clh; | 1016 | struct ClientLookupHandle *clh; |
1018 | char* nameptr = name; | 1017 | char* nameptr = name; |
1018 | const char *utf_in; | ||
1019 | int only_cached; | 1019 | int only_cached; |
1020 | struct GNUNET_CRYPTO_RsaPrivateKey *key; | 1020 | struct GNUNET_CRYPTO_RsaPrivateKey *key; |
1021 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey; | 1021 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey; |
1022 | char* tmp_pkey; | 1022 | char* tmp_pkey; |
1023 | 1023 | ||
1024 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) | 1024 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); |
1025 | msg_size = ntohs(message->size); | ||
1026 | if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage)) | ||
1025 | { | 1027 | { |
1026 | GNUNET_break (0); | 1028 | GNUNET_break (0); |
1027 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1029 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1028 | return; | 1030 | return; |
1029 | } | 1031 | } |
1030 | 1032 | sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message; | |
1031 | GNUNET_SERVER_notification_context_add (nc, client); | 1033 | GNUNET_SERVER_notification_context_add (nc, client); |
1032 | 1034 | if (GNUNET_YES == ntohl (sh_msg->have_key)) | |
1033 | struct GNUNET_GNS_ClientLookupMessage *sh_msg = | ||
1034 | (struct GNUNET_GNS_ClientLookupMessage *) message; | ||
1035 | |||
1036 | msg_size = ntohs(message->size); | ||
1037 | if (GNUNET_YES == ntohl(sh_msg->have_key)) | ||
1038 | { | 1035 | { |
1039 | pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *)&sh_msg[1]; | 1036 | pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *)&sh_msg[1]; |
1040 | tmp_pkey = (char*)&sh_msg[1]; | 1037 | tmp_pkey = (char*)&sh_msg[1]; |
@@ -1044,10 +1041,16 @@ handle_lookup(void *cls, | |||
1044 | else | 1041 | else |
1045 | { | 1042 | { |
1046 | key = NULL; | 1043 | key = NULL; |
1047 | GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); | 1044 | utf_in = (const char *) &sh_msg[1]; |
1048 | } | 1045 | if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientLookupMessage) - 1]) |
1049 | 1046 | { | |
1050 | namelen = strlen(name)+1; | 1047 | GNUNET_break (0); |
1048 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1049 | return; | ||
1050 | } | ||
1051 | GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr); | ||
1052 | } | ||
1053 | namelen = strlen (name)+1; | ||
1051 | clh = GNUNET_malloc (sizeof (struct ClientLookupHandle)); | 1054 | clh = GNUNET_malloc (sizeof (struct ClientLookupHandle)); |
1052 | memset (clh, 0, sizeof (struct ClientLookupHandle)); | 1055 | memset (clh, 0, sizeof (struct ClientLookupHandle)); |
1053 | clh->client = client; | 1056 | clh->client = client; |