aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-06 02:32:50 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-06 02:32:50 +0000
commit7df5bfca79c8ea68f1b80c1f2463d189352134f1 (patch)
treec78740afea1c1fa1405faf848f4302f5b452c870
parent0ca1ac02f452d992ddc9a4ce1b590aab350358e8 (diff)
downloadrspamd-7df5bfca79c8ea68f1b80c1f2463d189352134f1.tar.gz
rspamd-7df5bfca79c8ea68f1b80c1f2463d189352134f1.zip
Fix some errors
-rw-r--r--src/libcryptobox/keypair.c12
-rw-r--r--src/libutil/str_util.c4
-rw-r--r--src/rspamadm/keypair.c2
3 files changed, 10 insertions, 8 deletions
diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c
index 92beb592c..b1b5b112b 100644
--- a/src/libcryptobox/keypair.c
+++ b/src/libcryptobox/keypair.c
@@ -223,6 +223,8 @@ rspamd_keypair_new (enum rspamd_cryptobox_keypair_type type,
guint size;
kp = rspamd_cryptobox_keypair_alloc (type, alg);
+ kp->alg = alg;
+ kp->type = type;
sk = rspamd_cryptobox_keypair_sk (kp, &size);
pk = rspamd_cryptobox_keypair_pk (kp, &size);
@@ -235,12 +237,10 @@ rspamd_keypair_new (enum rspamd_cryptobox_keypair_type type,
}
rspamd_cryptobox_hash (kp->id, pk, size, NULL, 0);
- kp->alg = alg;
- kp->type = type;
REF_INIT_RETAIN (kp, rspamd_cryptobox_keypair_dtor);
- return pk;
+ return kp;
}
@@ -506,12 +506,13 @@ rspamd_keypair_print_component (guchar *data, gsize datalen,
gint olen, b32_len;
if (how & RSPAMD_KEYPAIR_HUMAN) {
- g_string_append_printf (res, "%s: ", description);
+ rspamd_printf_gstring (res, "%s: ", description);
}
if (how & RSPAMD_KEYPAIR_BASE32) {
b32_len = (datalen * 8 / 5) + 2;
g_string_set_size (res, res->len + b32_len);
+ res->len -= b32_len;
olen = rspamd_encode_base32_buf (data, datalen, res->str + res->len,
res->len + b32_len - 1);
@@ -541,7 +542,7 @@ rspamd_keypair_print (struct rspamd_cryptobox_keypair *kp, guint how)
g_assert (kp != NULL);
- res = g_string_sized_new (64);
+ res = g_string_sized_new (63);
if ((how & RSPAMD_KEYPAIR_PUBKEY)) {
p = rspamd_cryptobox_keypair_pk (kp, &len);
@@ -745,6 +746,7 @@ rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp,
ucl_object_insert_key (elt,
ucl_object_fromlstring (keypair_out->str, keypair_out->len),
"id", 0, false);
+ g_string_free (keypair_out, TRUE);
ucl_object_insert_key (elt,
ucl_object_fromstring (encoding),
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index c8f4088e1..f4bd75d69 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -1346,7 +1346,7 @@ rspamd_encode_hex_buf (const guchar *in, gsize inlen, gchar *out,
}
if (o <= end) {
- return (o - end);
+ return (o - out);
}
return -1;
@@ -1413,7 +1413,7 @@ rspamd_decode_hex_buf (const gchar *in, gsize inlen,
}
if (o <= end) {
- return (o - end);
+ return (o - out);
}
return -1;
diff --git a/src/rspamadm/keypair.c b/src/rspamadm/keypair.c
index 2cfbee972..ab1e25166 100644
--- a/src/rspamadm/keypair.c
+++ b/src/rspamadm/keypair.c
@@ -134,7 +134,7 @@ rspamadm_keypair (gint argc, gchar **argv)
}
out = rspamd_keypair_print (kp, how);
- rspamd_printf ("%v", kp);
+ rspamd_printf ("%v", out);
g_string_free (out, TRUE);
}