Please Clang's sanitizer.
authorAndy Polyakov <appro@openssl.org>
Tue, 8 Jul 2014 20:24:44 +0000 (22:24 +0200)
committerAndy Polyakov <appro@openssl.org>
Tue, 8 Jul 2014 20:24:44 +0000 (22:24 +0200)
PR: #3424,#3423,#3422

crypto/cast/cast_lcl.h
crypto/md32_common.h
crypto/modes/cbc128.c
crypto/modes/modes_lcl.h
crypto/rc4/rc4_enc.c
engines/ccgost/gost89.c
engines/ccgost/gost_crypt.c
ssl/heartbeat_test.c

index e756021a33dc3bc4fc50095255e90240947da74a..a2cf8faba9012efddb09fc04ad1f73646cb5635a 100644 (file)
 
 #if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
 #define ROTL(a,n)     (_lrotl(a,n))
 
 #if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
 #define ROTL(a,n)     (_lrotl(a,n))
+#elif defined(PEDANTIC)
+#define ROTL(a,n)     ((((a)<<(n))&0xffffffffL)|((a)>>((32-(n))&31)))
 #else
 #define ROTL(a,n)     ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
 #endif
 #else
 #define ROTL(a,n)     ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
 #endif
index 147a7a00c30e3649ad5695cc49b3776a0720d594..1b84104354e91a38ca5456702210e3d343c8165c 100644 (file)
 #   endif
 #  endif
 # endif
 #   endif
 #  endif
 # endif
-#endif
-#if defined(__s390__) || defined(__s390x__)
-# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, (l))
-# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, (l))
+# if defined(__s390__) || defined(__s390x__)
+#  define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, (l))
+#  define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, (l))
+# endif
 #endif
 
 #ifndef HOST_c2l
 #endif
 
 #ifndef HOST_c2l
                                   (c)+=4; (l);                         })
 #  endif
 # endif
                                   (c)+=4; (l);                         })
 #  endif
 # endif
-#endif
-#if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
-# ifndef B_ENDIAN
-   /* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */
-#  define HOST_c2l(c,l)        ((l)=*((const unsigned int *)(c)), (c)+=4, l)
-#  define HOST_l2c(l,c)        (*((unsigned int *)(c))=(l), (c)+=4, l)
+# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
+#  ifndef B_ENDIAN
+    /* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */
+#   define HOST_c2l(c,l)       ((l)=*((const unsigned int *)(c)), (c)+=4, l)
+#   define HOST_l2c(l,c)       (*((unsigned int *)(c))=(l), (c)+=4, l)
+#  endif
 # endif
 #endif
 
 # endif
 #endif
 
index 0e54f75470b2fbba3b85289ec845b9e7bfb8ec4e..8c9bdea4aa9bc107e775fbfacba8274ccc0a257e 100644 (file)
@@ -59,7 +59,7 @@
 #endif
 #include <assert.h>
 
 #endif
 #include <assert.h>
 
-#ifndef STRICT_ALIGNMENT
+#if !defined(STRICT_ALIGNMENT) && !defined(PEDANTIC)
 #  define STRICT_ALIGNMENT 0
 #endif
 
 #  define STRICT_ALIGNMENT 0
 #endif
 
index 35d4d9fa53a024839731e8e10891008ad765e5ad..2d7015aea62d985d58f6cd678907b64f96b7d4ba 100644 (file)
@@ -26,6 +26,7 @@ typedef unsigned int u32;
 typedef unsigned char u8;
 
 #define STRICT_ALIGNMENT 1
 typedef unsigned char u8;
 
 #define STRICT_ALIGNMENT 1
+#ifndef PEDANTIC
 #if defined(__i386)    || defined(__i386__)    || \
     defined(__x86_64)  || defined(__x86_64__)  || \
     defined(_M_IX86)   || defined(_M_AMD64)    || defined(_M_X64) || \
 #if defined(__i386)    || defined(__i386__)    || \
     defined(__x86_64)  || defined(__x86_64__)  || \
     defined(_M_IX86)   || defined(_M_AMD64)    || defined(_M_X64) || \
@@ -33,6 +34,7 @@ typedef unsigned char u8;
     defined(__s390__)  || defined(__s390x__)
 # undef STRICT_ALIGNMENT
 #endif
     defined(__s390__)  || defined(__s390x__)
 # undef STRICT_ALIGNMENT
 #endif
+#endif
 
 #if !defined(PEDANTIC) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
 #if defined(__GNUC__) && __GNUC__>=2
 
 #if !defined(PEDANTIC) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
 #if defined(__GNUC__) && __GNUC__>=2
index 8c4fc6c7a3da38451da27f8b429ef340d2684a40..0cc5ac471f6169ebc423c6902bf2a1fd8b84a8d7 100644 (file)
@@ -78,7 +78,7 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
         y=key->y;     
         d=key->data; 
 
         y=key->y;     
         d=key->data; 
 
-#if defined(RC4_CHUNK)
+#if defined(RC4_CHUNK) && !defined(PEDANTIC)
        /*
         * The original reason for implementing this(*) was the fact that
         * pre-21164a Alpha CPUs don't have byte load/store instructions
        /*
         * The original reason for implementing this(*) was the fact that
         * pre-21164a Alpha CPUs don't have byte load/store instructions
index b0568c6b3c8446e1dd5f1432b90f93f674e42400..c1474cb652715e1cf177a39a39762382d1a2adcb 100644 (file)
@@ -120,7 +120,7 @@ static void kboxinit(gost_ctx *c, const gost_subst_block *b)
        
        for (i = 0; i < 256; i++)
                {
        
        for (i = 0; i < 256; i++)
                {
-               c->k87[i] = (b->k8[i>>4] <<4 | b->k7 [i &15])<<24;
+               c->k87[i] = (word32)(b->k8[i>>4] <<4 | b->k7 [i &15])<<24;
                c->k65[i] = (b->k6[i>>4] << 4 | b->k5 [i &15])<<16;
                c->k43[i] = (b->k4[i>>4] <<4  | b->k3 [i &15])<<8;
                c->k21[i] = b->k2[i>>4] <<4  | b->k1 [i &15];
                c->k65[i] = (b->k6[i>>4] << 4 | b->k5 [i &15])<<16;
                c->k43[i] = (b->k4[i>>4] <<4  | b->k3 [i &15])<<8;
                c->k21[i] = b->k2[i>>4] <<4  | b->k1 [i &15];
@@ -140,8 +140,8 @@ static word32 f(gost_ctx *c,word32 x)
 void gostcrypt(gost_ctx *c, const byte *in, byte *out)
        { 
        register word32 n1, n2; /* As named in the GOST */ 
 void gostcrypt(gost_ctx *c, const byte *in, byte *out)
        { 
        register word32 n1, n2; /* As named in the GOST */ 
-       n1 = in[0]|(in[1]<<8)|(in[2]<<16)|(in[3]<<24); 
-       n2 = in[4]|(in[5]<<8)|(in[6]<<16)|(in[7]<<24); 
+       n1 = in[0]|(in[1]<<8)|(in[2]<<16)|((word32)in[3]<<24); 
+       n2 = in[4]|(in[5]<<8)|(in[6]<<16)|((word32)in[7]<<24); 
        /* Instead of swapping halves, swap names each round */ 
         
        n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
        /* Instead of swapping halves, swap names each round */ 
         
        n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
@@ -173,8 +173,8 @@ void gostcrypt(gost_ctx *c, const byte *in, byte *out)
 void gostdecrypt(gost_ctx *c, const byte *in,byte *out)
        { 
        register word32 n1, n2; /* As named in the GOST */ 
 void gostdecrypt(gost_ctx *c, const byte *in,byte *out)
        { 
        register word32 n1, n2; /* As named in the GOST */ 
-       n1 = in[0]|(in[1]<<8)|(in[2]<<16)|(in[3]<<24); 
-       n2 = in[4]|(in[5]<<8)|(in[6]<<16)|(in[7]<<24); 
+       n1 = in[0]|(in[1]<<8)|(in[2]<<16)|((word32)in[3]<<24); 
+       n2 = in[4]|(in[5]<<8)|(in[6]<<16)|((word32)in[7]<<24); 
        
        n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
        n2 ^= f(c,n1+c->k[2]); n1 ^= f(c,n2+c->k[3]); 
        
        n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
        n2 ^= f(c,n1+c->k[2]); n1 ^= f(c,n2+c->k[3]); 
@@ -275,7 +275,7 @@ void gost_key(gost_ctx *c, const byte *k)
        int i,j; 
        for(i=0,j=0;i<8;i++,j+=4)
                {
        int i,j; 
        for(i=0,j=0;i<8;i++,j+=4)
                {
-               c->k[i]=k[j]|(k[j+1]<<8)|(k[j+2]<<16)|(k[j+3]<<24);
+               c->k[i]=k[j]|(k[j+1]<<8)|(k[j+2]<<16)|((word32)k[j+3]<<24);
                }               
        } 
 
                }               
        } 
 
@@ -323,8 +323,8 @@ void mac_block(gost_ctx *c,byte *buffer,const  byte *block)
                {
                buffer[i]^=block[i];
                }         
                {
                buffer[i]^=block[i];
                }         
-       n1 = buffer[0]|(buffer[1]<<8)|(buffer[2]<<16)|(buffer[3]<<24); 
-       n2 = buffer[4]|(buffer[5]<<8)|(buffer[6]<<16)|(buffer[7]<<24); 
+       n1 = buffer[0]|(buffer[1]<<8)|(buffer[2]<<16)|((word32)buffer[3]<<24); 
+       n2 = buffer[4]|(buffer[5]<<8)|(buffer[6]<<16)|((word32)buffer[7]<<24); 
        /* Instead of swapping halves, swap names each round */ 
         
        n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
        /* Instead of swapping halves, swap names each round */ 
         
        n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
index 52aef15acf4b93db5c078bed22112a9cb2502b41..15ab02aabb79135eddcc0f181dffce9140b0c954 100644 (file)
@@ -241,13 +241,13 @@ static void gost_cnt_next (void *ctx, unsigned char *iv, unsigned char *buf)
                {
                memcpy(buf1,iv,8);
                }       
                {
                memcpy(buf1,iv,8);
                }       
-       g = buf1[0]|(buf1[1]<<8)|(buf1[2]<<16)|(buf1[3]<<24);
+       g = buf1[0]|(buf1[1]<<8)|(buf1[2]<<16)|((word32)buf1[3]<<24);
        g += 0x01010101;
        buf1[0]=(unsigned char)(g&0xff);
        buf1[1]=(unsigned char)((g>>8)&0xff);
        buf1[2]=(unsigned char)((g>>16)&0xff);
        buf1[3]=(unsigned char)((g>>24)&0xff);
        g += 0x01010101;
        buf1[0]=(unsigned char)(g&0xff);
        buf1[1]=(unsigned char)((g>>8)&0xff);
        buf1[2]=(unsigned char)((g>>16)&0xff);
        buf1[3]=(unsigned char)((g>>24)&0xff);
-       g = buf1[4]|(buf1[5]<<8)|(buf1[6]<<16)|(buf1[7]<<24);
+       g = buf1[4]|(buf1[5]<<8)|(buf1[6]<<16)|((word32)buf1[7]<<24);
        go = g;
        g += 0x01010104;
        if (go > g)      /*  overflow*/
        go = g;
        g += 0x01010104;
        if (go > g)      /*  overflow*/
index a0a3690096d504e74881c062852f3a6cdfa065c6..287fc1682597e49f16bc31414a177e163c38eafc 100644 (file)
@@ -273,7 +273,8 @@ static int test_dtls1_not_bleeding()
        {
        SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
        /* Three-byte pad at the beginning for type and payload length */
        {
        SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
        /* Three-byte pad at the beginning for type and payload length */
-       unsigned char payload_buf[] = "   Not bleeding, sixteen spaces of padding"
+       unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS+4] =
+               "   Not bleeding, sixteen spaces of padding"
                "                ";
        const int payload_buf_len = honest_payload_size(payload_buf);
 
                "                ";
        const int payload_buf_len = honest_payload_size(payload_buf);
 
@@ -292,9 +293,9 @@ static int test_dtls1_not_bleeding_empty_payload()
        SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
        /* Three-byte pad at the beginning for type and payload length, plus a NUL
         * at the end */
        SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
        /* Three-byte pad at the beginning for type and payload length, plus a NUL
         * at the end */
-       unsigned char payload_buf[4 + MIN_PADDING_SIZE];
-       memset(payload_buf, ' ', sizeof(payload_buf));
-       payload_buf[sizeof(payload_buf) - 1] = '\0';
+       unsigned char payload_buf[4 + MAX_PRINTABLE_CHARACTERS];
+       memset(payload_buf, ' ', MIN_PADDING_SIZE+3);
+       payload_buf[MIN_PADDING_SIZE+3] = '\0';
        payload_buf_len = honest_payload_size(payload_buf);
 
        fixture.payload = &payload_buf[0];
        payload_buf_len = honest_payload_size(payload_buf);
 
        fixture.payload = &payload_buf[0];
@@ -309,7 +310,8 @@ static int test_dtls1_heartbleed()
        {
        SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
        /* Three-byte pad at the beginning for type and payload length */
        {
        SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
        /* Three-byte pad at the beginning for type and payload length */
-       unsigned char payload_buf[] = "   HEARTBLEED                ";
+       unsigned char payload_buf[4+MAX_PRINTABLE_CHARACTERS] =
+               "   HEARTBLEED                ";
 
        fixture.payload = &payload_buf[0];
        fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
 
        fixture.payload = &payload_buf[0];
        fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
@@ -324,9 +326,9 @@ static int test_dtls1_heartbleed_empty_payload()
        SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
        /* Excluding the NUL at the end, one byte short of type + payload length +
         * minimum padding */
        SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
        /* Excluding the NUL at the end, one byte short of type + payload length +
         * minimum padding */
-       unsigned char payload_buf[MIN_PADDING_SIZE + 3];
-       memset(payload_buf, ' ', sizeof(payload_buf));
-       payload_buf[sizeof(payload_buf) - 1] = '\0';
+       unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4];
+       memset(payload_buf, ' ', MIN_PADDING_SIZE+2);
+       payload_buf[MIN_PADDING_SIZE+2] = '\0';
 
        fixture.payload = &payload_buf[0];
        fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
 
        fixture.payload = &payload_buf[0];
        fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
@@ -357,8 +359,9 @@ static int test_tls1_not_bleeding()
        {
        SETUP_HEARTBEAT_TEST_FIXTURE(tls);
        /* Three-byte pad at the beginning for type and payload length */
        {
        SETUP_HEARTBEAT_TEST_FIXTURE(tls);
        /* Three-byte pad at the beginning for type and payload length */
-       unsigned char payload_buf[] = "   Not bleeding, sixteen spaces of padding"
-                                       "                ";
+       unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS+4] =
+                       "   Not bleeding, sixteen spaces of padding"
+                       "                ";
        const int payload_buf_len = honest_payload_size(payload_buf);
 
        fixture.payload = &payload_buf[0];
        const int payload_buf_len = honest_payload_size(payload_buf);
 
        fixture.payload = &payload_buf[0];
@@ -376,9 +379,9 @@ static int test_tls1_not_bleeding_empty_payload()
        SETUP_HEARTBEAT_TEST_FIXTURE(tls);
        /* Three-byte pad at the beginning for type and payload length, plus a NUL
         * at the end */
        SETUP_HEARTBEAT_TEST_FIXTURE(tls);
        /* Three-byte pad at the beginning for type and payload length, plus a NUL
         * at the end */
-       unsigned char payload_buf[4 + MIN_PADDING_SIZE];
-       memset(payload_buf, ' ', sizeof(payload_buf));
-       payload_buf[sizeof(payload_buf) - 1] = '\0';
+       unsigned char payload_buf[4 + MAX_PRINTABLE_CHARACTERS];
+       memset(payload_buf, ' ', MIN_PADDING_SIZE+3);
+       payload_buf[MIN_PADDING_SIZE+3] = '\0';
        payload_buf_len = honest_payload_size(payload_buf);
 
        fixture.payload = &payload_buf[0];
        payload_buf_len = honest_payload_size(payload_buf);
 
        fixture.payload = &payload_buf[0];
@@ -393,7 +396,8 @@ static int test_tls1_heartbleed()
        {
        SETUP_HEARTBEAT_TEST_FIXTURE(tls);
        /* Three-byte pad at the beginning for type and payload length */
        {
        SETUP_HEARTBEAT_TEST_FIXTURE(tls);
        /* Three-byte pad at the beginning for type and payload length */
-       unsigned char payload_buf[] = "   HEARTBLEED                ";
+       unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS+4] =
+                       "   HEARTBLEED                ";
 
        fixture.payload = &payload_buf[0];
        fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
 
        fixture.payload = &payload_buf[0];
        fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
@@ -408,9 +412,9 @@ static int test_tls1_heartbleed_empty_payload()
        SETUP_HEARTBEAT_TEST_FIXTURE(tls);
        /* Excluding the NUL at the end, one byte short of type + payload length +
         * minimum padding */
        SETUP_HEARTBEAT_TEST_FIXTURE(tls);
        /* Excluding the NUL at the end, one byte short of type + payload length +
         * minimum padding */
-       unsigned char payload_buf[MIN_PADDING_SIZE + 3];
-       memset(payload_buf, ' ', sizeof(payload_buf));
-       payload_buf[sizeof(payload_buf) - 1] = '\0';
+       unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4];
+       memset(payload_buf, ' ', MIN_PADDING_SIZE+2);
+       payload_buf[MIN_PADDING_SIZE+2] = '\0';
 
        fixture.payload = &payload_buf[0];
        fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
 
        fixture.payload = &payload_buf[0];
        fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;