[gnome-keyring] Fix incorrect loop condition in egg_hkdf_perform()
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] Fix incorrect loop condition in egg_hkdf_perform()
- Date: Tue, 23 Oct 2012 19:46:38 +0000 (UTC)
commit 3156ac7c5e20e7fd2cb7096d6401165fb033ee78
Author: Xi Wang <xi wang gmail com>
Date: Mon Oct 22 16:09:46 2012 -0400
Fix incorrect loop condition in egg_hkdf_perform()
This does not cause a change in behavior (as evidenced by tests,
at least on linux when built with gcc) but is more correct code,
and less likely to be miscompiled.
The condition (i < 256) in the following loop is always false since i
is of type guchar, which is at most 255.
guchar i;
...
for (i = 1; i < 256; ++i) { ... }
This patch changes i to a larger type gint.
Also in the loop we have:
gcry_md_write (md2, &i, 1);
change it to use gcry_md_putc().
egg/egg-hkdf.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/egg/egg-hkdf.c b/egg/egg-hkdf.c
index e5ab86e..cfd597a 100644
--- a/egg/egg-hkdf.c
+++ b/egg/egg-hkdf.c
@@ -39,7 +39,7 @@ egg_hkdf_perform (const gchar *hash_algo, gconstpointer input, gsize n_input,
gpointer buffer = NULL;
gcry_md_hd_t md1, md2;
guint hash_len;
- guchar i;
+ gint i;
gint flags, algo;
gsize step, n_buffer;
guchar *at;
@@ -89,7 +89,7 @@ egg_hkdf_perform (const gchar *hash_algo, gconstpointer input, gsize n_input,
gcry_md_reset (md2);
gcry_md_write (md2, buffer, n_buffer);
gcry_md_write (md2, info, n_info);
- gcry_md_write (md2, &i, 1);
+ gcry_md_putc (md2, i);
n_buffer = hash_len;
memcpy (buffer, gcry_md_read (md2, algo), n_buffer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]