From 9579febbd6c9993b7408f7006e4f9cd8e78f345d Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sun, 7 Feb 2010 16:34:37 -0500 Subject: [PATCH] Since guint64 is really an unsigned long dont cast it as unsigned long long in places. Also in set_unset_common() use a guint64 and strtoul() to detect negative values (syntax errors). --- src/commands.c | 20 ++++++++++---------- src/pwmd.c | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/commands.c b/src/commands.c index 7fa5580b..007da65e 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1196,7 +1196,7 @@ gpg_error_t update_save_flags(const gchar *filename, if (filename && !crypto->fh->v1) { iter = (guint64)get_key_file_double(filename, "iterations"); - crypto->fh->ver.fh2.iter = iter < 0ULL ? 0ULL : iter; + crypto->fh->ver.fh2.iter = iter < 0L ? 0UL : iter; } return 0; @@ -1356,7 +1356,7 @@ static gpg_error_t save_command(assuan_context_t ctx, gchar *line) memset(client->crypto->key, '!', hashlen); - if (get_key_file_double(client->filename, "iterations") <= 0) + if (get_key_file_double(client->filename, "iterations") <= 0L) goto done; if (!line || !*line) { @@ -2665,7 +2665,7 @@ static gpg_error_t getconfig_command(assuan_context_t ctx, gchar *line) if (!rc) { g_free(paramp); - p = g_strdup_printf("%llu", fh->ver.fh2.iter); + p = g_strdup_printf("%lu", (unsigned long)fh->ver.fh2.iter); close_file_header(fh); if (!p) { @@ -3129,7 +3129,7 @@ static gint set_unset_common(assuan_context_t ctx, const gchar *name, goto done; } else if (g_ascii_strcasecmp(name, (gchar *)"iterations") == 0) { - gdouble n; + guint64 n; gchar *p = NULL; if (!client->filename) @@ -3140,15 +3140,15 @@ static gint set_unset_common(assuan_context_t ctx, const gchar *name, g_key_file_set_double(keyfileh, client->filename, "iterations", get_key_file_double("global", "iterations")); MUTEX_UNLOCK(&rcfile_mutex); - log_write1("iterations=%llu", - get_key_file_double(client->filename, "iterations")); + log_write1("iterations=%lu", + (guint64)get_key_file_double(client->filename, "iterations")); goto done; } errno = 0; - n = strtoll(value, &p, 10); + n = strtoul(value, &p, 10); - if (errno || (p && *p) || n < 0ULL) + if (errno || (p && *p) || n == G_MAXULONG) return gpg_err_make(PWMD_ERR_SOURCE, GPG_ERR_INV_VALUE); MUTEX_LOCK(&rcfile_mutex); @@ -3159,7 +3159,7 @@ static gint set_unset_common(assuan_context_t ctx, const gchar *name, if (client->filename) client->opts |= OPT_ITERATIONS; - log_write1("iterations=%llu", n); + log_write1("iterations=%lu", n); goto done; } else if (g_ascii_strcasecmp(name, (gchar *)"NAME") == 0) { @@ -3563,7 +3563,7 @@ gpg_error_t try_xml_decrypt(assuan_context_t ctx, guchar *key, /* No encryption iterations. This is a plain (gzipped) file. */ if ((crypto->fh->v1 && (long)fh_iter < 0L) || - (!crypto->fh->v1 && fh_iter <= 0ULL)) { + (!crypto->fh->v1 && fh_iter <= 0L)) { /* * cache_file_count() needs both .used == TRUE and a valid key in * order for it to count as a used cache entry. Fixes CACHE status diff --git a/src/pwmd.c b/src/pwmd.c index da1e4b1b..726caaae 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -726,8 +726,8 @@ static void set_rcfile_defaults(GKeyFile *kf) g_key_file_set_integer(kf, "global", "cache_timeout", -1); if (g_key_file_has_key(kf, "global", "iterations", NULL) == FALSE || - g_key_file_get_double(kf, "global", "iterations", 0) < 0ULL) - g_key_file_set_double(kf, "global", "iterations", 1ULL); + g_key_file_get_double(kf, "global", "iterations", 0) < 0L) + g_key_file_set_double(kf, "global", "iterations", 1UL); if (g_key_file_has_key(kf, "global", "disable_list_and_dump", NULL) == FALSE) g_key_file_set_boolean(kf, "global", "disable_list_and_dump", FALSE); @@ -2051,7 +2051,8 @@ int main(int argc, char *argv[]) gchar *p; gchar **cache_push = NULL; gchar *import = NULL, *keyfile = NULL; - guint64 cmd_iterations = -1ULL; + guint64 cmd_iterations = 0UL; + gboolean iterations_arg = FALSE; gint default_timeout; gboolean rcfile_spec = FALSE; gint estatus = EXIT_FAILURE; @@ -2194,7 +2195,14 @@ int main(int argc, char *argv[]) import = optarg; break; case 'i': - cmd_iterations = strtoll(optarg, NULL, 10); + cmd_iterations = strtoul(optarg, NULL, 10); + + if (cmd_iterations == G_MAXULONG) { + log_write("%s", N_("invalid iteration count")); + usage(argv[0], EXIT_FAILURE); + } + + iterations_arg = TRUE; break; case 'k': keyfile = optarg; @@ -2263,7 +2271,7 @@ int main(int argc, char *argv[]) if (!outfile) usage(argv[0], EXIT_FAILURE); - if (cmd_iterations == -1ULL) + if (!iterations_arg) cmd_iterations = (guint64)get_key_file_double("global", "iterations"); opt = xml_import(import, outfile, keyfile, cmd_iterations); -- 2.11.4.GIT