From 0f616348a45cc97f618239cc7eba0a3343769881 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=D0=B5x=D0=B0nder=20Lysik=D0=BEv?=
 <alexander.lysikov@demlabs.net>
Date: Tue, 4 Feb 2020 17:03:51 +0500
Subject: [PATCH] fixed dap_chain_str_to_hash_fast()

---
 src/dap_enc_key.c |  2 +-
 src/dap_hash.c    | 14 ++++++++------
 src/dap_sign.c    |  2 ++
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/dap_enc_key.c b/src/dap_enc_key.c
index 332eb6b..38eee1a 100755
--- a/src/dap_enc_key.c
+++ b/src/dap_enc_key.c
@@ -493,7 +493,7 @@ dap_enc_key_serealize_t* dap_enc_key_serealize(dap_enc_key_t * key)
 dap_enc_key_t* dap_enc_key_deserealize(const void *buf, size_t buf_size)
 {
     if(buf_size != sizeof (dap_enc_key_serealize_t)) {
-        log_it(L_ERROR, "Key can't be deserealize. buf_size != sizeof (dap_enc_key_serealize_t)");
+        log_it(L_ERROR, "Key can't be deserealize. buf_size(%d) != sizeof (dap_enc_key_serealize_t)(%d)",buf_size,sizeof (dap_enc_key_serealize_t));
         return NULL;
     }
     const dap_enc_key_serealize_t *in_key = (const dap_enc_key_serealize_t *)buf;
diff --git a/src/dap_hash.c b/src/dap_hash.c
index 27db3c7..6842f63 100755
--- a/src/dap_hash.c
+++ b/src/dap_hash.c
@@ -42,12 +42,14 @@ int dap_chain_str_to_hash_fast( const char * a_hash_str, dap_chain_hash_fast_t *
     const size_t c_hash_str_size = sizeof(*a_hash) * 2 + 1 /*trailing zero*/+ 2 /* heading 0x */;
     size_t l_hash_str_len = strlen( a_hash_str);
     if ( l_hash_str_len + 1 == c_hash_str_size ){
-        for (size_t l_offset = 2; l_offset < l_hash_str_len; l_offset+=2 ){
-            if ( ( sscanf(a_hash_str+l_offset,"%02hhx",a_hash->raw+l_offset/2-1) != 1) ||
-                 ( sscanf(a_hash_str+l_offset,"%02hhX",a_hash->raw+l_offset/2-1) != 1)
-                 )
-                log_it(L_ERROR,"dap_chain_str_to_hash_fast parse error: offset=%u, hash_str_len=%u, str=\"%2s\"",l_offset, l_hash_str_len, a_hash_str+l_offset);
-                return -10* ((int) l_offset); // Wrong char
+        for(size_t l_offset = 2; l_offset < l_hash_str_len; l_offset += 2) {
+            if(sscanf(a_hash_str + l_offset, "%02hhx", a_hash->raw + l_offset / 2 - 1) != 1) {
+                if(sscanf(a_hash_str + l_offset, "%02hhX", a_hash->raw + l_offset / 2 - 1) != 1) {
+                    log_it(L_ERROR, "dap_chain_str_to_hash_fast parse error: offset=%u, hash_str_len=%u, str=\"%2s\"",
+                            l_offset, l_hash_str_len, a_hash_str + l_offset);
+                    return -10 * ((int) l_offset); // Wrong char
+                }
+            }
         }
         return  0;
     }else  // Wromg string len
diff --git a/src/dap_sign.c b/src/dap_sign.c
index 3e221c8..f2b6d54 100755
--- a/src/dap_sign.c
+++ b/src/dap_sign.c
@@ -40,6 +40,8 @@ static bliss_signature_t s_sign_bliss_null = {0};
 // calc signature size
 size_t dap_sign_create_output_unserialized_calc_size(dap_enc_key_t * a_key, size_t a_output_wish_size )
 {
+    if(!a_key)
+        return 0;
     size_t l_sign_size = 0;
     switch (a_key->type){
         case DAP_ENC_KEY_TYPE_SIG_BLISS: l_sign_size = sizeof(s_sign_bliss_null); break;
-- 
GitLab