diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/configuration.c | 62 | ||||
-rw-r--r-- | src/util/disk.c | 51 | ||||
-rw-r--r-- | src/util/getopt.c | 8 | ||||
-rw-r--r-- | src/util/getopt_helpers.c | 25 | ||||
-rw-r--r-- | src/util/gnunet-service-resolver.c | 18 | ||||
-rw-r--r-- | src/util/service.c | 18 | ||||
-rw-r--r-- | src/util/strings.c | 43 |
7 files changed, 155 insertions, 70 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index e00bbd64a..197c664db 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -138,6 +138,41 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) | |||
138 | 138 | ||
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Parse a configuration file @a filename and run the function | ||
142 | * @a cb with the resulting configuration object. Then free the | ||
143 | * configuration object and return the status value from @a cb. | ||
144 | * | ||
145 | * @param filename configuration to parse, NULL for "default" | ||
146 | * @param cb function to run | ||
147 | * @param cb_cls closure for @a cb | ||
148 | * @return #GNUNET_SYSERR if parsing the configuration failed, | ||
149 | * otherwise return value from @a cb. | ||
150 | */ | ||
151 | int | ||
152 | GNUNET_CONFIGURATION_parse_and_run (const char *filename, | ||
153 | GNUNET_CONFIGURATION_Callback cb, | ||
154 | void *cb_cls) | ||
155 | { | ||
156 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
157 | int ret; | ||
158 | |||
159 | cfg = GNUNET_CONFIGURATION_create (); | ||
160 | if (GNUNET_OK != | ||
161 | GNUNET_CONFIGURATION_load (cfg, | ||
162 | filename)) | ||
163 | { | ||
164 | GNUNET_break (0); | ||
165 | GNUNET_CONFIGURATION_destroy (cfg); | ||
166 | return GNUNET_SYSERR; | ||
167 | } | ||
168 | ret = cb (cb_cls, | ||
169 | cfg); | ||
170 | GNUNET_CONFIGURATION_destroy (cfg); | ||
171 | return ret; | ||
172 | } | ||
173 | |||
174 | |||
175 | /** | ||
141 | * De-serializes configuration | 176 | * De-serializes configuration |
142 | * | 177 | * |
143 | * @param cfg configuration to update | 178 | * @param cfg configuration to update |
@@ -522,7 +557,7 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
522 | GNUNET_free (fn); | 557 | GNUNET_free (fn); |
523 | GNUNET_free (cfg_buf); | 558 | GNUNET_free (cfg_buf); |
524 | LOG (GNUNET_ERROR_TYPE_WARNING, | 559 | LOG (GNUNET_ERROR_TYPE_WARNING, |
525 | "Writing configration to file `%s' failed\n", | 560 | "Writing configuration to file `%s' failed\n", |
526 | filename); | 561 | filename); |
527 | cfg->dirty = GNUNET_SYSERR; /* last write failed */ | 562 | cfg->dirty = GNUNET_SYSERR; /* last write failed */ |
528 | return GNUNET_SYSERR; | 563 | return GNUNET_SYSERR; |
@@ -893,22 +928,27 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
893 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 928 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
894 | */ | 929 | */ |
895 | int | 930 | int |
896 | GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle | 931 | GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg, |
897 | *cfg, const char *section, | 932 | const char *section, |
898 | const char *option, | 933 | const char *option, |
899 | unsigned long long *number) | 934 | unsigned long long *number) |
900 | { | 935 | { |
901 | struct ConfigEntry *e; | 936 | struct ConfigEntry *e; |
937 | char dummy[2]; | ||
902 | 938 | ||
903 | if (NULL == (e = find_entry (cfg, section, option))) | 939 | if (NULL == (e = find_entry (cfg, section, option))) |
904 | return GNUNET_SYSERR; | 940 | return GNUNET_SYSERR; |
905 | if (NULL == e->val) | 941 | if (NULL == e->val) |
906 | return GNUNET_SYSERR; | 942 | return GNUNET_SYSERR; |
907 | if (1 != SSCANF (e->val, "%llu", number)) | 943 | if (1 != SSCANF (e->val, |
944 | "%llu%1s", | ||
945 | number, | ||
946 | dummy)) | ||
908 | return GNUNET_SYSERR; | 947 | return GNUNET_SYSERR; |
909 | return GNUNET_OK; | 948 | return GNUNET_OK; |
910 | } | 949 | } |
911 | 950 | ||
951 | |||
912 | /** | 952 | /** |
913 | * Get a configuration value that should be a floating point number. | 953 | * Get a configuration value that should be a floating point number. |
914 | * | 954 | * |
@@ -919,18 +959,22 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle | |||
919 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 959 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
920 | */ | 960 | */ |
921 | int | 961 | int |
922 | GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle | 962 | GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg, |
923 | *cfg, const char *section, | 963 | const char *section, |
924 | const char *option, | 964 | const char *option, |
925 | float *number) | 965 | float *number) |
926 | { | 966 | { |
927 | struct ConfigEntry *e; | 967 | struct ConfigEntry *e; |
928 | 968 | char dummy[2]; | |
969 | |||
929 | if (NULL == (e = find_entry (cfg, section, option))) | 970 | if (NULL == (e = find_entry (cfg, section, option))) |
930 | return GNUNET_SYSERR; | 971 | return GNUNET_SYSERR; |
931 | if (NULL == e->val) | 972 | if (NULL == e->val) |
932 | return GNUNET_SYSERR; | 973 | return GNUNET_SYSERR; |
933 | if (1 != SSCANF (e->val, "%f", number)) | 974 | if (1 != SSCANF (e->val, |
975 | "%f%1s", | ||
976 | number, | ||
977 | dummy)) | ||
934 | return GNUNET_SYSERR; | 978 | return GNUNET_SYSERR; |
935 | return GNUNET_OK; | 979 | return GNUNET_OK; |
936 | } | 980 | } |
diff --git a/src/util/disk.c b/src/util/disk.c index e0227be70..dc38d1137 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -2668,28 +2668,19 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, | |||
2668 | 2668 | ||
2669 | 2669 | ||
2670 | /** | 2670 | /** |
2671 | * Remove the directory given under @a option in | 2671 | * Helper function for #GNUNET_DISK_purge_cfg_dir. |
2672 | * section [PATHS] in configuration under @a cfg_filename | ||
2673 | * | 2672 | * |
2674 | * @param cfg_filename configuration file to parse | 2673 | * @param cls a `const char *` with the option to purge |
2675 | * @param option option with the dir name to purge | 2674 | * @param cfg our configuration |
2675 | * @return #GNUNET_OK on success | ||
2676 | */ | 2676 | */ |
2677 | void | 2677 | static int |
2678 | GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, | 2678 | purge_cfg_dir (void *cls, |
2679 | const char *option) | 2679 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
2680 | { | 2680 | { |
2681 | struct GNUNET_CONFIGURATION_Handle *cfg; | 2681 | const char *option = cls; |
2682 | char *tmpname; | 2682 | char *tmpname; |
2683 | 2683 | ||
2684 | cfg = GNUNET_CONFIGURATION_create (); | ||
2685 | if (GNUNET_OK != | ||
2686 | GNUNET_CONFIGURATION_load (cfg, | ||
2687 | cfg_filename)) | ||
2688 | { | ||
2689 | GNUNET_break (0); | ||
2690 | GNUNET_CONFIGURATION_destroy (cfg); | ||
2691 | return; | ||
2692 | } | ||
2693 | if (GNUNET_OK != | 2684 | if (GNUNET_OK != |
2694 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 2685 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
2695 | "PATHS", | 2686 | "PATHS", |
@@ -2699,10 +2690,8 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, | |||
2699 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 2690 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
2700 | "PATHS", | 2691 | "PATHS", |
2701 | option); | 2692 | option); |
2702 | GNUNET_CONFIGURATION_destroy (cfg); | 2693 | return GNUNET_NO; |
2703 | return; | ||
2704 | } | 2694 | } |
2705 | GNUNET_CONFIGURATION_destroy (cfg); | ||
2706 | if (GNUNET_SYSERR == | 2695 | if (GNUNET_SYSERR == |
2707 | GNUNET_DISK_directory_remove (tmpname)) | 2696 | GNUNET_DISK_directory_remove (tmpname)) |
2708 | { | 2697 | { |
@@ -2710,11 +2699,29 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, | |||
2710 | "remove", | 2699 | "remove", |
2711 | tmpname); | 2700 | tmpname); |
2712 | GNUNET_free (tmpname); | 2701 | GNUNET_free (tmpname); |
2713 | return; | 2702 | return GNUNET_OK; |
2714 | } | 2703 | } |
2715 | GNUNET_free (tmpname); | 2704 | GNUNET_free (tmpname); |
2705 | return GNUNET_OK; | ||
2716 | } | 2706 | } |
2717 | 2707 | ||
2718 | 2708 | ||
2709 | /** | ||
2710 | * Remove the directory given under @a option in | ||
2711 | * section [PATHS] in configuration under @a cfg_filename | ||
2712 | * | ||
2713 | * @param cfg_filename configuration file to parse | ||
2714 | * @param option option with the dir name to purge | ||
2715 | */ | ||
2716 | void | ||
2717 | GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, | ||
2718 | const char *option) | ||
2719 | { | ||
2720 | GNUNET_break (GNUNET_OK == | ||
2721 | GNUNET_CONFIGURATION_parse_and_run (cfg_filename, | ||
2722 | &purge_cfg_dir, | ||
2723 | (void *) option)); | ||
2724 | } | ||
2725 | |||
2719 | 2726 | ||
2720 | /* end of disk.c */ | 2727 | /* end of disk.c */ |
diff --git a/src/util/getopt.c b/src/util/getopt.c index 036e0f4be..4a7f35f51 100644 --- a/src/util/getopt.c +++ b/src/util/getopt.c | |||
@@ -866,7 +866,7 @@ GNgetopt_long (int argc, | |||
866 | * @param argc number of arguments | 866 | * @param argc number of arguments |
867 | * @param argv actual arguments | 867 | * @param argv actual arguments |
868 | * @return index into argv with first non-option | 868 | * @return index into argv with first non-option |
869 | * argument, or -1 on error | 869 | * argument, or #GNUNET_SYSERR on error |
870 | */ | 870 | */ |
871 | int | 871 | int |
872 | GNUNET_GETOPT_run (const char *binaryOptions, | 872 | GNUNET_GETOPT_run (const char *binaryOptions, |
@@ -967,9 +967,9 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
967 | GNUNET_free (seen); | 967 | GNUNET_free (seen); |
968 | 968 | ||
969 | /* call cleaners, if available */ | 969 | /* call cleaners, if available */ |
970 | for (count = 0; NULL != allOptions[count].name; count++) | 970 | for (unsigned int i = 0; NULL != allOptions[i].name; i++) |
971 | if (NULL != allOptions[count].cleaner) | 971 | if (NULL != allOptions[i].cleaner) |
972 | allOptions[count].cleaner (allOptions[count].scls); | 972 | allOptions[i].cleaner (allOptions[i].scls); |
973 | 973 | ||
974 | if (GNUNET_OK != cont) | 974 | if (GNUNET_OK != cont) |
975 | return cont; | 975 | return cont; |
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index 32cce65dd..661521c45 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c | |||
@@ -108,9 +108,10 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
108 | (void) value; | 108 | (void) value; |
109 | if (NULL != about) | 109 | if (NULL != about) |
110 | { | 110 | { |
111 | printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); | 111 | printf ("%s\n%s\n", |
112 | printf (_ | 112 | ctx->binaryOptions, |
113 | ("Arguments mandatory for long options are also mandatory for short options.\n")); | 113 | gettext (about)); |
114 | printf (_("Arguments mandatory for long options are also mandatory for short options.\n")); | ||
114 | } | 115 | } |
115 | i = 0; | 116 | i = 0; |
116 | opt = ctx->allOptions; | 117 | opt = ctx->allOptions; |
@@ -549,11 +550,13 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
549 | const char *value) | 550 | const char *value) |
550 | { | 551 | { |
551 | unsigned long long *val = scls; | 552 | unsigned long long *val = scls; |
553 | char dummy[2]; | ||
552 | 554 | ||
553 | (void) ctx; | 555 | (void) ctx; |
554 | if (1 != SSCANF (value, | 556 | if (1 != SSCANF (value, |
555 | "%llu", | 557 | "%llu%1s", |
556 | val)) | 558 | val, |
559 | dummy)) | ||
557 | { | 560 | { |
558 | FPRINTF (stderr, | 561 | FPRINTF (stderr, |
559 | _("You must pass a number to the `%s' option.\n"), | 562 | _("You must pass a number to the `%s' option.\n"), |
@@ -746,6 +749,7 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
746 | const char *value) | 749 | const char *value) |
747 | { | 750 | { |
748 | unsigned int *val = scls; | 751 | unsigned int *val = scls; |
752 | char dummy[2]; | ||
749 | 753 | ||
750 | (void) ctx; | 754 | (void) ctx; |
751 | if('-' == *value) | 755 | if('-' == *value) |
@@ -756,8 +760,9 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
756 | return GNUNET_SYSERR; | 760 | return GNUNET_SYSERR; |
757 | } | 761 | } |
758 | if (1 != SSCANF (value, | 762 | if (1 != SSCANF (value, |
759 | "%u", | 763 | "%u%1s", |
760 | val)) | 764 | val, |
765 | dummy)) | ||
761 | { | 766 | { |
762 | FPRINTF (stderr, | 767 | FPRINTF (stderr, |
763 | _("You must pass a number to the `%s' option.\n"), | 768 | _("You must pass a number to the `%s' option.\n"), |
@@ -820,11 +825,13 @@ set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
820 | { | 825 | { |
821 | uint16_t *val = scls; | 826 | uint16_t *val = scls; |
822 | unsigned int v; | 827 | unsigned int v; |
828 | char dummy[2]; | ||
823 | 829 | ||
824 | (void) ctx; | 830 | (void) ctx; |
825 | if (1 != SSCANF (value, | 831 | if (1 != SSCANF (value, |
826 | "%u", | 832 | "%u%1s", |
827 | &v)) | 833 | &v, |
834 | dummy)) | ||
828 | { | 835 | { |
829 | FPRINTF (stderr, | 836 | FPRINTF (stderr, |
830 | _("You must pass a number to the `%s' option.\n"), | 837 | _("You must pass a number to the `%s' option.\n"), |
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index d907bd8d9..3b871ce33 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -364,7 +364,7 @@ lookup_dns_servers (char ***server_addrs) | |||
364 | GNUNET_DISK_file_close (fh); | 364 | GNUNET_DISK_file_close (fh); |
365 | return -1; | 365 | return -1; |
366 | } | 366 | } |
367 | if (bytes_read > SIZE_MAX) | 367 | if ((size_t) bytes_read > SIZE_MAX) |
368 | { | 368 | { |
369 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 369 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
370 | "/etc/resolv.conf file too large to mmap. " | 370 | "/etc/resolv.conf file too large to mmap. " |
@@ -379,7 +379,7 @@ lookup_dns_servers (char ***server_addrs) | |||
379 | *server_addrs = NULL; | 379 | *server_addrs = NULL; |
380 | read_offset = 0; | 380 | read_offset = 0; |
381 | num_dns_servers = 0; | 381 | num_dns_servers = 0; |
382 | while (read_offset < bytes_read) | 382 | while (read_offset < (size_t) bytes_read) |
383 | { | 383 | { |
384 | const char *newline; | 384 | const char *newline; |
385 | size_t line_len; | 385 | size_t line_len; |
@@ -648,11 +648,16 @@ try_cache (const char *hostname, | |||
648 | struct ResolveCache *pos; | 648 | struct ResolveCache *pos; |
649 | struct ResolveCache *next; | 649 | struct ResolveCache *next; |
650 | int found; | 650 | int found; |
651 | int in_hosts; | ||
651 | 652 | ||
653 | in_hosts = GNUNET_NO; | ||
652 | for (pos = hosts_head; NULL != pos; pos = pos->next) | 654 | for (pos = hosts_head; NULL != pos; pos = pos->next) |
653 | if (0 == strcmp (pos->hostname, | 655 | if (0 == strcmp (pos->hostname, |
654 | hostname)) | 656 | hostname)) |
657 | { | ||
658 | in_hosts = GNUNET_YES; | ||
655 | break; | 659 | break; |
660 | } | ||
656 | if (NULL == pos) | 661 | if (NULL == pos) |
657 | { | 662 | { |
658 | next = cache_head; | 663 | next = cache_head; |
@@ -673,7 +678,8 @@ try_cache (const char *hostname, | |||
673 | hostname); | 678 | hostname); |
674 | return GNUNET_NO; | 679 | return GNUNET_NO; |
675 | } | 680 | } |
676 | if (cache_head != pos) | 681 | if ( (GNUNET_NO == in_hosts) && |
682 | (cache_head != pos) ) | ||
677 | { | 683 | { |
678 | /* move result to head to achieve LRU for cache eviction */ | 684 | /* move result to head to achieve LRU for cache eviction */ |
679 | GNUNET_CONTAINER_DLL_remove (cache_head, | 685 | GNUNET_CONTAINER_DLL_remove (cache_head, |
@@ -1313,7 +1319,7 @@ extract_hosts (const char *line, | |||
1313 | if (NULL != c) | 1319 | if (NULL != c) |
1314 | line_len = c - line; | 1320 | line_len = c - line; |
1315 | /* ignore leading whitespace */ | 1321 | /* ignore leading whitespace */ |
1316 | while ( (0 > line_len) && | 1322 | while ( (0 < line_len) && |
1317 | isspace ((unsigned char) *line) ) | 1323 | isspace ((unsigned char) *line) ) |
1318 | { | 1324 | { |
1319 | line++; | 1325 | line++; |
@@ -1382,7 +1388,7 @@ load_etc_hosts (void) | |||
1382 | GNUNET_DISK_file_close (fh); | 1388 | GNUNET_DISK_file_close (fh); |
1383 | return; | 1389 | return; |
1384 | } | 1390 | } |
1385 | if (bytes_read > SIZE_MAX) | 1391 | if ((size_t) bytes_read > SIZE_MAX) |
1386 | { | 1392 | { |
1387 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1393 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1388 | "/etc/hosts file too large to mmap. " | 1394 | "/etc/hosts file too large to mmap. " |
@@ -1395,7 +1401,7 @@ load_etc_hosts (void) | |||
1395 | GNUNET_DISK_MAP_TYPE_READ, | 1401 | GNUNET_DISK_MAP_TYPE_READ, |
1396 | (size_t) bytes_read); | 1402 | (size_t) bytes_read); |
1397 | read_offset = 0; | 1403 | read_offset = 0; |
1398 | while (read_offset < bytes_read) | 1404 | while (read_offset < (size_t) bytes_read) |
1399 | { | 1405 | { |
1400 | const char *newline; | 1406 | const char *newline; |
1401 | size_t line_len; | 1407 | size_t line_len; |
diff --git a/src/util/service.c b/src/util/service.c index 20cc1036d..b61168570 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -1175,8 +1175,9 @@ setup_service (struct GNUNET_SERVICE_Handle *sh) | |||
1175 | const char *nfds; | 1175 | const char *nfds; |
1176 | unsigned int cnt; | 1176 | unsigned int cnt; |
1177 | int flags; | 1177 | int flags; |
1178 | char dummy[2]; | ||
1178 | #endif | 1179 | #endif |
1179 | 1180 | ||
1180 | if (GNUNET_CONFIGURATION_have_value | 1181 | if (GNUNET_CONFIGURATION_have_value |
1181 | (sh->cfg, | 1182 | (sh->cfg, |
1182 | sh->service_name, | 1183 | sh->service_name, |
@@ -1203,8 +1204,9 @@ setup_service (struct GNUNET_SERVICE_Handle *sh) | |||
1203 | errno = 0; | 1204 | errno = 0; |
1204 | if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) && | 1205 | if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) && |
1205 | (1 == SSCANF (nfds, | 1206 | (1 == SSCANF (nfds, |
1206 | "%u", | 1207 | "%u%1s", |
1207 | &cnt)) && | 1208 | &cnt, |
1209 | dummy)) && | ||
1208 | (cnt > 0) && | 1210 | (cnt > 0) && |
1209 | (cnt < FD_SETSIZE) && | 1211 | (cnt < FD_SETSIZE) && |
1210 | (cnt + 4 < FD_SETSIZE) ) | 1212 | (cnt + 4 < FD_SETSIZE) ) |
@@ -1813,8 +1815,9 @@ GNUNET_SERVICE_run_ (int argc, | |||
1813 | opt_cfg_filename = GNUNET_strdup (cfg_filename); | 1815 | opt_cfg_filename = GNUNET_strdup (cfg_filename); |
1814 | if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_filename)) | 1816 | if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_filename)) |
1815 | { | 1817 | { |
1816 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, | 1818 | if (GNUNET_SYSERR == |
1817 | opt_cfg_filename)) | 1819 | GNUNET_CONFIGURATION_load (cfg, |
1820 | opt_cfg_filename)) | ||
1818 | { | 1821 | { |
1819 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1822 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1820 | _("Malformed configuration file `%s', exit ...\n"), | 1823 | _("Malformed configuration file `%s', exit ...\n"), |
@@ -1824,8 +1827,9 @@ GNUNET_SERVICE_run_ (int argc, | |||
1824 | } | 1827 | } |
1825 | else | 1828 | else |
1826 | { | 1829 | { |
1827 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, | 1830 | if (GNUNET_SYSERR == |
1828 | NULL)) | 1831 | GNUNET_CONFIGURATION_load (cfg, |
1832 | NULL)) | ||
1829 | { | 1833 | { |
1830 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1834 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1831 | _("Malformed configuration, exit ...\n")); | 1835 | _("Malformed configuration, exit ...\n")); |
diff --git a/src/util/strings.c b/src/util/strings.c index b7a7fcb8b..3f85384e1 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -1262,6 +1262,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, | |||
1262 | int ret; | 1262 | int ret; |
1263 | char *port_colon; | 1263 | char *port_colon; |
1264 | unsigned int port; | 1264 | unsigned int port; |
1265 | char dummy[2]; | ||
1265 | 1266 | ||
1266 | if (addrlen < 6) | 1267 | if (addrlen < 6) |
1267 | return GNUNET_SYSERR; | 1268 | return GNUNET_SYSERR; |
@@ -1286,7 +1287,10 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, | |||
1286 | _("IPv6 address did contain ']' before ':' to separate port number\n")); | 1287 | _("IPv6 address did contain ']' before ':' to separate port number\n")); |
1287 | return GNUNET_SYSERR; | 1288 | return GNUNET_SYSERR; |
1288 | } | 1289 | } |
1289 | ret = SSCANF (port_colon, ":%u", &port); | 1290 | ret = SSCANF (port_colon, |
1291 | ":%u%1s", | ||
1292 | &port, | ||
1293 | dummy); | ||
1290 | if ( (1 != ret) || (port > 65535) ) | 1294 | if ( (1 != ret) || (port > 65535) ) |
1291 | { | 1295 | { |
1292 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1296 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1332,16 +1336,18 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, | |||
1332 | unsigned int temps[4]; | 1336 | unsigned int temps[4]; |
1333 | unsigned int port; | 1337 | unsigned int port; |
1334 | unsigned int cnt; | 1338 | unsigned int cnt; |
1339 | char dummy[2]; | ||
1335 | 1340 | ||
1336 | if (addrlen < 9) | 1341 | if (addrlen < 9) |
1337 | return GNUNET_SYSERR; | 1342 | return GNUNET_SYSERR; |
1338 | cnt = SSCANF (zt_addr, | 1343 | cnt = SSCANF (zt_addr, |
1339 | "%u.%u.%u.%u:%u", | 1344 | "%u.%u.%u.%u:%u%1s", |
1340 | &temps[0], | 1345 | &temps[0], |
1341 | &temps[1], | 1346 | &temps[1], |
1342 | &temps[2], | 1347 | &temps[2], |
1343 | &temps[3], | 1348 | &temps[3], |
1344 | &port); | 1349 | &port, |
1350 | dummy); | ||
1345 | if (5 != cnt) | 1351 | if (5 != cnt) |
1346 | return GNUNET_SYSERR; | 1352 | return GNUNET_SYSERR; |
1347 | for (cnt = 0; cnt < 4; cnt++) | 1353 | for (cnt = 0; cnt < 4; cnt++) |
@@ -1563,7 +1569,9 @@ parse_port_policy (const char *port_policy, | |||
1563 | } | 1569 | } |
1564 | if (2 == sscanf (pos, | 1570 | if (2 == sscanf (pos, |
1565 | "%u-%u%1s", | 1571 | "%u-%u%1s", |
1566 | &s, &e, eol)) | 1572 | &s, |
1573 | &e, | ||
1574 | eol)) | ||
1567 | { | 1575 | { |
1568 | if ( (0 == s) || | 1576 | if ( (0 == s) || |
1569 | (s > 0xFFFF) || | 1577 | (s > 0xFFFF) || |
@@ -1629,7 +1637,8 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) | |||
1629 | int colon; | 1637 | int colon; |
1630 | int end; | 1638 | int end; |
1631 | char *routeList; | 1639 | char *routeList; |
1632 | 1640 | char dummy[2]; | |
1641 | |||
1633 | if (NULL == routeListX) | 1642 | if (NULL == routeListX) |
1634 | return NULL; | 1643 | return NULL; |
1635 | len = strlen (routeListX); | 1644 | len = strlen (routeListX); |
@@ -1664,7 +1673,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) | |||
1664 | } | 1673 | } |
1665 | cnt = | 1674 | cnt = |
1666 | SSCANF (&routeList[pos], | 1675 | SSCANF (&routeList[pos], |
1667 | "%u.%u.%u.%u/%u.%u.%u.%u", | 1676 | "%u.%u.%u.%u/%u.%u.%u.%u%1s", |
1668 | &temps[0], | 1677 | &temps[0], |
1669 | &temps[1], | 1678 | &temps[1], |
1670 | &temps[2], | 1679 | &temps[2], |
@@ -1672,7 +1681,8 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) | |||
1672 | &temps[4], | 1681 | &temps[4], |
1673 | &temps[5], | 1682 | &temps[5], |
1674 | &temps[6], | 1683 | &temps[6], |
1675 | &temps[7]); | 1684 | &temps[7], |
1685 | dummy); | ||
1676 | if (8 == cnt) | 1686 | if (8 == cnt) |
1677 | { | 1687 | { |
1678 | for (j = 0; j < 8; j++) | 1688 | for (j = 0; j < 8; j++) |
@@ -1698,12 +1708,13 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) | |||
1698 | /* try second notation */ | 1708 | /* try second notation */ |
1699 | cnt = | 1709 | cnt = |
1700 | SSCANF (&routeList[pos], | 1710 | SSCANF (&routeList[pos], |
1701 | "%u.%u.%u.%u/%u", | 1711 | "%u.%u.%u.%u/%u%1s", |
1702 | &temps[0], | 1712 | &temps[0], |
1703 | &temps[1], | 1713 | &temps[1], |
1704 | &temps[2], | 1714 | &temps[2], |
1705 | &temps[3], | 1715 | &temps[3], |
1706 | &slash); | 1716 | &slash, |
1717 | dummy); | ||
1707 | if (5 == cnt) | 1718 | if (5 == cnt) |
1708 | { | 1719 | { |
1709 | for (j = 0; j < 4; j++) | 1720 | for (j = 0; j < 4; j++) |
@@ -1747,11 +1758,12 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) | |||
1747 | slash = 32; | 1758 | slash = 32; |
1748 | cnt = | 1759 | cnt = |
1749 | SSCANF (&routeList[pos], | 1760 | SSCANF (&routeList[pos], |
1750 | "%u.%u.%u.%u", | 1761 | "%u.%u.%u.%u%1s", |
1751 | &temps[0], | 1762 | &temps[0], |
1752 | &temps[1], | 1763 | &temps[1], |
1753 | &temps[2], | 1764 | &temps[2], |
1754 | &temps[3]); | 1765 | &temps[3], |
1766 | dummy); | ||
1755 | if (4 == cnt) | 1767 | if (4 == cnt) |
1756 | { | 1768 | { |
1757 | for (j = 0; j < 4; j++) | 1769 | for (j = 0; j < 4; j++) |
@@ -1826,7 +1838,8 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX) | |||
1826 | unsigned int off; | 1838 | unsigned int off; |
1827 | int save; | 1839 | int save; |
1828 | int colon; | 1840 | int colon; |
1829 | 1841 | char dummy[2]; | |
1842 | |||
1830 | if (NULL == routeListX) | 1843 | if (NULL == routeListX) |
1831 | return NULL; | 1844 | return NULL; |
1832 | len = strlen (routeListX); | 1845 | len = strlen (routeListX); |
@@ -1886,7 +1899,11 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX) | |||
1886 | if (ret <= 0) | 1899 | if (ret <= 0) |
1887 | { | 1900 | { |
1888 | save = errno; | 1901 | save = errno; |
1889 | if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits > 128)) | 1902 | if ( (1 != SSCANF (&routeList[slash + 1], |
1903 | "%u%1s", | ||
1904 | &bits, | ||
1905 | dummy)) || | ||
1906 | (bits > 128) ) | ||
1890 | { | 1907 | { |
1891 | if (0 == ret) | 1908 | if (0 == ret) |
1892 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1909 | LOG (GNUNET_ERROR_TYPE_WARNING, |