Avoid sign extension when shifting the MSB.
authorWerner Koch <wk@gnupg.org>
Wed, 5 Nov 2014 07:23:15 +0000 (08:23 +0100)
committerWerner Koch <wk@gnupg.org>
Wed, 5 Nov 2014 07:23:15 +0000 (08:23 +0100)
* sm/fingerprint.c (gpgsm_get_short_fingerprint): Cast MSB before
shifting.
* g10/build-packet.c (delete_sig_subpkt): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
g10/build-packet.c
sm/fingerprint.c

index c04abab..6bd1c9b 100644 (file)
@@ -618,8 +618,10 @@ delete_sig_subpkt (subpktarea_t *area, sigsubpkttype_t reqtype )
        if( n == 255 ) {
            if( buflen < 4 )
                break;
        if( n == 255 ) {
            if( buflen < 4 )
                break;
-           n = (buffer[0] << 24) | (buffer[1] << 16)
-                | (buffer[2] << 8) | buffer[3];
+           n = (((size_t)buffer[0] << 24)
+                 | (buffer[1] << 16)
+                 | (buffer[2] << 8)
+                 | buffer[3]);
            buffer += 4;
            buflen -= 4;
        }
            buffer += 4;
            buflen -= 4;
        }
index b0c7608..b849afb 100644 (file)
@@ -149,8 +149,14 @@ gpgsm_get_short_fingerprint (ksba_cert_t cert, unsigned long *r_high)
 
   gpgsm_get_fingerprint (cert, GCRY_MD_SHA1, digest, NULL);
   if (r_high)
 
   gpgsm_get_fingerprint (cert, GCRY_MD_SHA1, digest, NULL);
   if (r_high)
-    *r_high = ((digest[12]<<24)|(digest[13]<<16)|(digest[14]<< 8)|digest[15]);
-  return ((digest[16]<<24)|(digest[17]<<16)|(digest[18]<< 8)|digest[19]);
+    *r_high = (((unsigned long)digest[12]<<24)
+               |(digest[13]<<16)
+               |(digest[14]<< 8)
+               |digest[15]);
+  return (((unsigned long)digest[16]<<24)
+          |(digest[17]<<16)
+          |(digest[18]<<8)
+          |digest[19]);
 }
 
 \f
 }
 
 \f