]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Fix bug with libzrtp zrtp_signaling_hash_set()
authorViktor Krykun <viktor@krykun.com>
Thu, 21 Jun 2012 08:36:33 +0000 (11:36 +0300)
committerTravis Cross <tc@traviscross.com>
Mon, 11 Feb 2013 16:42:01 +0000 (16:42 +0000)
The function would silently not accept the imported zrtp-hash-value
with "buffer too small" in the debug output.

Modified-by: Travis Cross <tc@traviscross.com>
Signed-off-by: Travis Cross <tc@traviscross.com>
libs/libzrtp/doc/manuals/changelog.dox
libs/libzrtp/include/zrtp.h
libs/libzrtp/src/zrtp.c
libs/libzrtp/src/zrtp_string.c

index 36f8117b622745f2921befcf692819b353eabefc..42fdae34d0e53de5c7f1c22f040a0ae193b91907 100644 (file)
@@ -34,6 +34,8 @@
 ***\subsection v120_bugs Bug fixes
   *- fixed bug when ZRTP forces enrolled endpoints to re-render SAS when sashash is empty.
   *- other minor bug fixes and improvements
+  *- fixed bug when zrtp_signaling_hash_set() silently not accepted imported zrtp-hash-value with 
+     "buffer too small" debug output.
 
 
 ****************************************************************************************************
index 67c64a8eebe559d21fd6ead055734f17261c39c8..3b5e5f67af16aa774640aacf0587616232d4842b 100644 (file)
@@ -82,6 +82,9 @@
  * \ingroup zrtp_main_init 
  */
 
+/** Length of "zrtp-hash-value", RFC 6189 sec 8. @sa zrtp_signaling_hash_get(); */
+#define ZRTP_SIGN_ZRTP_HASH_LENGTH     (ZRTP_MESSAGE_HASH_SIZE*2)
+
 /**
  * \brief Enumeration for ZRTP Licensing modes
  * \ingroup zrtp_main_init 
@@ -798,7 +801,7 @@ zrtp_status_t  zrtp_process_srtcp( zrtp_stream_t *stream,
  * 
  * \param stream - stream for operating with;
  * \param hash_buff - signaling hash buffer. Function accepts string, not a binary value!;
- * \param hash_buff_length - signaling hash length in bytes (must be 64 bytes);
+ * \param hash_buff_length - signaling hash length in bytes, must be ZRTP_SIGN_ZRTP_HASH_LENGTH bytes;
  * \return:
  *  - zrtp_status_ok if the operation finished successfully
  *  - one of the errors otherwise
@@ -819,8 +822,8 @@ zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* stream,
  *
  * \param stream - stream for operating with
  * \param hash_buff - buffer for storing signaling hash. Function returns already parsed hex string.
- *      String is null-terminated.
- * \param hash_buff_length - buffer length in bytes (not shorter than 65 bytes)
+ *      String is null-terminated. Buffer must be at least ZRTP_SIGN_ZRTP_HASH_LENGTH bytes length.
+ * \param hash_buff_length - buffer length in bytes, non less  than ZRTP_SIGN_ZRTP_HASH_LENGTH bytes.
  * \return:
  *  - zrtp_status_ok if the operation finished successfully
  *  - one of the errors otherwise
index 9ee078082be5eaf45f8f30b391b515c7ad54d4fd..05be53dfafcedbdd0d14254638130ad927e0a4d9 100644 (file)
@@ -437,8 +437,6 @@ zrtp_status_t zrtp_stream_attach(zrtp_session_t *session, zrtp_stream_t** stream
        ZSTR_SET_EMPTY(new_stream->cc.peer_hmackey);
        ZSTR_SET_EMPTY(new_stream->cc.zrtp_key);
        ZSTR_SET_EMPTY(new_stream->cc.peer_zrtp_key);
-       
-       ZSTR_SET_EMPTY(new_stream->messages.signaling_hash);
 
        new_stream->dh_cc.initialized_with      = ZRTP_COMP_UNKN;
        bnBegin(&new_stream->dh_cc.peer_pv);
@@ -466,6 +464,7 @@ zrtp_status_t zrtp_stream_attach(zrtp_session_t *session, zrtp_stream_t** stream
 
        zrtp_memset(&new_stream->messages, 0, sizeof(new_stream->messages));    
        ZSTR_SET_EMPTY(new_stream->messages.h0);
+       ZSTR_SET_EMPTY(new_stream->messages.signaling_hash);
 
        /* Generate Random nonce, compute H1 and store in the DH packet */
        new_stream->messages.h0.length = (uint16_t)zrtp_randstr( new_stream->zrtp,
@@ -595,11 +594,11 @@ zrtp_status_t zrtp_signaling_hash_get( zrtp_stream_t* stream,
        zrtp_string32_t hash_str = ZSTR_INIT_EMPTY(hash_str);
        zrtp_hash_t *hash = NULL;
 
-       if (!stream) {
+       if (!stream || !hash_buff) {
                return zrtp_status_bad_param;
        }
 
-       if (ZRTP_MESSAGE_HASH_SIZE*2+1 > hash_buff_length) {
+       if (ZRTP_SIGN_ZRTP_HASH_LENGTH > hash_buff_length) {
                return zrtp_status_buffer_size;
        }
 
@@ -622,11 +621,11 @@ zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* ctx,
                                                                           const char *hash_buff,
                                                                           uint32_t hash_buff_length)
 {
-       if (!ctx) {
+       if (!ctx || !hash_buff) {
                return zrtp_status_bad_param;
        }
 
-       if (ZRTP_MESSAGE_HASH_SIZE*2 < hash_buff_length) {
+       if (ZRTP_SIGN_ZRTP_HASH_LENGTH > hash_buff_length) {
                return zrtp_status_buffer_size;
        }
 
@@ -634,17 +633,14 @@ zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* ctx,
                return zrtp_status_wrong_state;
        }
        
-       str2hex( hash_buff,
-                    hash_buff_length,
-                        ctx->messages.signaling_hash.buffer,
-                        ctx->messages.signaling_hash.max_length);
+       str2hex(hash_buff,
+                       ZRTP_SIGN_ZRTP_HASH_LENGTH,
+                       ctx->messages.signaling_hash.buffer,
+                       ctx->messages.signaling_hash.max_length);
        ctx->messages.signaling_hash.length = ZRTP_MESSAGE_HASH_SIZE;
        
-       {
-       char buff[64];
-       ZRTP_LOG(3, (_ZTU_,"SIGNALLING HAS was ADDED for the comparision. ID=%u\n", ctx->id));
-       ZRTP_LOG(3, (_ZTU_,"Hash=%s.\n", hex2str(hash_buff, hash_buff_length, buff, sizeof(buff))));
-       }
+       ZRTP_LOG(3, (_ZTU_,"SIGNALLING HAS was ADDED for the comparison. ID=%u\n", ctx->id));
+       ZRTP_LOG(3, (_ZTU_,"Hash=%.*s.\n", ZRTP_SIGN_ZRTP_HASH_LENGTH, hash_buff));
 
        return zrtp_status_ok;
 }
index 2c7814005176079b4f178d0ff9a21373d4f64e80..162dbca2f9ee6f66c55a88a31c6b4c40f85ba4c0 100644 (file)
@@ -113,7 +113,7 @@ const char* hex2str(const char* bin, int bin_size, char* buff, int buff_size)
        if (NULL == buff) {
                return "buffer is NULL";
        }               
-       if (buff_size < bin_size*2+1) {
+       if (buff_size < bin_size*2) {
                return "buffer too small";
        }
        
@@ -121,7 +121,8 @@ const char* hex2str(const char* bin, int bin_size, char* buff, int buff_size)
                nptr = hex2char(nptr, *bin++);
        }
        
-       *nptr = 0;
+       if (buff_size >= bin_size*2+1)
+               *nptr = 0;
        
        return buff;
 }