]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix some errors
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 6 Feb 2016 02:32:50 +0000 (02:32 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 6 Feb 2016 02:32:50 +0000 (02:32 +0000)
src/libcryptobox/keypair.c
src/libutil/str_util.c
src/rspamadm/keypair.c

index 92beb592c7ddcafd83881ceb54716360aa5b6f1f..b1b5b112b8cf7b4afc2d2e54ce9e226af619880f 100644 (file)
@@ -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),
index c8f4088e196ec6b0cdb90717a4fa9d668a4ec88f..f4bd75d6956f5f956bf18a14d9611fff7cd24b7e 100644 (file)
@@ -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;
index 2cfbee97203ec96ebac38b3a49649d3f910e4cbf..ab1e251667b91956fc12a031515c4c2ec89d581b 100644 (file)
@@ -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);
        }