From 3a4e51894442b7fdde457836c6f99d710e47b3f1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 4 Nov 2018 11:17:09 +0100 Subject: fix #5454 --- src/util/configuration.c | 25 +++++++++++++++++-------- src/util/getopt.c | 8 ++++---- src/util/getopt_helpers.c | 25 ++++++++++++++++--------- src/util/service.c | 8 +++++--- src/util/strings.c | 43 ++++++++++++++++++++++++++++++------------- 5 files changed, 72 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/util/configuration.c b/src/util/configuration.c index e00bbd64a..41eb3188d 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -893,22 +893,27 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, +GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, unsigned long long *number) { struct ConfigEntry *e; + char dummy[2]; if (NULL == (e = find_entry (cfg, section, option))) return GNUNET_SYSERR; if (NULL == e->val) return GNUNET_SYSERR; - if (1 != SSCANF (e->val, "%llu", number)) + if (1 != SSCANF (e->val, + "%llu%1s", + number, + dummy)) return GNUNET_SYSERR; - return GNUNET_OK; + return GNUNET_OK; } + /** * Get a configuration value that should be a floating point number. * @@ -919,18 +924,22 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, +GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, float *number) { struct ConfigEntry *e; - + char dummy[2]; + if (NULL == (e = find_entry (cfg, section, option))) return GNUNET_SYSERR; if (NULL == e->val) return GNUNET_SYSERR; - if (1 != SSCANF (e->val, "%f", number)) + if (1 != SSCANF (e->val, + "%f%1s", + number, + dummy)) return GNUNET_SYSERR; return GNUNET_OK; } 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, * @param argc number of arguments * @param argv actual arguments * @return index into argv with first non-option - * argument, or -1 on error + * argument, or #GNUNET_SYSERR on error */ int GNUNET_GETOPT_run (const char *binaryOptions, @@ -967,9 +967,9 @@ GNUNET_GETOPT_run (const char *binaryOptions, GNUNET_free (seen); /* call cleaners, if available */ - for (count = 0; NULL != allOptions[count].name; count++) - if (NULL != allOptions[count].cleaner) - allOptions[count].cleaner (allOptions[count].scls); + for (unsigned int i = 0; NULL != allOptions[i].name; i++) + if (NULL != allOptions[i].cleaner) + allOptions[i].cleaner (allOptions[i].scls); if (GNUNET_OK != cont) 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, (void) value; if (NULL != about) { - printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); - printf (_ - ("Arguments mandatory for long options are also mandatory for short options.\n")); + printf ("%s\n%s\n", + ctx->binaryOptions, + gettext (about)); + printf (_("Arguments mandatory for long options are also mandatory for short options.\n")); } i = 0; opt = ctx->allOptions; @@ -549,11 +550,13 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, const char *value) { unsigned long long *val = scls; + char dummy[2]; (void) ctx; if (1 != SSCANF (value, - "%llu", - val)) + "%llu%1s", + val, + dummy)) { FPRINTF (stderr, _("You must pass a number to the `%s' option.\n"), @@ -746,6 +749,7 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, const char *value) { unsigned int *val = scls; + char dummy[2]; (void) ctx; if('-' == *value) @@ -756,8 +760,9 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, return GNUNET_SYSERR; } if (1 != SSCANF (value, - "%u", - val)) + "%u%1s", + val, + dummy)) { FPRINTF (stderr, _("You must pass a number to the `%s' option.\n"), @@ -820,11 +825,13 @@ set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, { uint16_t *val = scls; unsigned int v; + char dummy[2]; (void) ctx; if (1 != SSCANF (value, - "%u", - &v)) + "%u%1s", + &v, + dummy)) { FPRINTF (stderr, _("You must pass a number to the `%s' option.\n"), diff --git a/src/util/service.c b/src/util/service.c index 20cc1036d..ea34abc6c 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -1175,8 +1175,9 @@ setup_service (struct GNUNET_SERVICE_Handle *sh) const char *nfds; unsigned int cnt; int flags; + char dummy[2]; #endif - + if (GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, @@ -1203,8 +1204,9 @@ setup_service (struct GNUNET_SERVICE_Handle *sh) errno = 0; if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) && (1 == SSCANF (nfds, - "%u", - &cnt)) && + "%u%1s", + &cnt, + dummy)) && (cnt > 0) && (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE) ) 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, int ret; char *port_colon; unsigned int port; + char dummy[2]; if (addrlen < 6) return GNUNET_SYSERR; @@ -1286,7 +1287,10 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, _("IPv6 address did contain ']' before ':' to separate port number\n")); return GNUNET_SYSERR; } - ret = SSCANF (port_colon, ":%u", &port); + ret = SSCANF (port_colon, + ":%u%1s", + &port, + dummy); if ( (1 != ret) || (port > 65535) ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -1332,16 +1336,18 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, unsigned int temps[4]; unsigned int port; unsigned int cnt; + char dummy[2]; if (addrlen < 9) return GNUNET_SYSERR; cnt = SSCANF (zt_addr, - "%u.%u.%u.%u:%u", + "%u.%u.%u.%u:%u%1s", &temps[0], &temps[1], &temps[2], &temps[3], - &port); + &port, + dummy); if (5 != cnt) return GNUNET_SYSERR; for (cnt = 0; cnt < 4; cnt++) @@ -1563,7 +1569,9 @@ parse_port_policy (const char *port_policy, } if (2 == sscanf (pos, "%u-%u%1s", - &s, &e, eol)) + &s, + &e, + eol)) { if ( (0 == s) || (s > 0xFFFF) || @@ -1629,7 +1637,8 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) int colon; int end; char *routeList; - + char dummy[2]; + if (NULL == routeListX) return NULL; len = strlen (routeListX); @@ -1664,7 +1673,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) } cnt = SSCANF (&routeList[pos], - "%u.%u.%u.%u/%u.%u.%u.%u", + "%u.%u.%u.%u/%u.%u.%u.%u%1s", &temps[0], &temps[1], &temps[2], @@ -1672,7 +1681,8 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) &temps[4], &temps[5], &temps[6], - &temps[7]); + &temps[7], + dummy); if (8 == cnt) { for (j = 0; j < 8; j++) @@ -1698,12 +1708,13 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) /* try second notation */ cnt = SSCANF (&routeList[pos], - "%u.%u.%u.%u/%u", + "%u.%u.%u.%u/%u%1s", &temps[0], &temps[1], &temps[2], &temps[3], - &slash); + &slash, + dummy); if (5 == cnt) { for (j = 0; j < 4; j++) @@ -1747,11 +1758,12 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) slash = 32; cnt = SSCANF (&routeList[pos], - "%u.%u.%u.%u", + "%u.%u.%u.%u%1s", &temps[0], &temps[1], &temps[2], - &temps[3]); + &temps[3], + dummy); if (4 == cnt) { for (j = 0; j < 4; j++) @@ -1826,7 +1838,8 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX) unsigned int off; int save; int colon; - + char dummy[2]; + if (NULL == routeListX) return NULL; len = strlen (routeListX); @@ -1886,7 +1899,11 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX) if (ret <= 0) { save = errno; - if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits > 128)) + if ( (1 != SSCANF (&routeList[slash + 1], + "%u%1s", + &bits, + dummy)) || + (bits > 128) ) { if (0 == ret) LOG (GNUNET_ERROR_TYPE_WARNING, -- cgit v1.2.3