Unsigned chars can't be negative
authorMatt Caswell <matt@openssl.org>
Mon, 18 Apr 2016 14:12:58 +0000 (15:12 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 18 Apr 2016 14:12:58 +0000 (15:12 +0100)
Fix a problem where an unsigned char was being checked to see if it was
negative.

Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/o_str.c

index 9811e2df2b9517f2559acf2d993a595e53474400..660226fcec5fbc3ab8f305de8328cbc2ab137e0d 100644 (file)
@@ -243,6 +243,7 @@ unsigned char *OPENSSL_hexstr2buf(const char *str, long *len)
 {
     unsigned char *hexbuf, *q;
     unsigned char ch, cl;
+    int chi, cli;
     const unsigned char *p;
     size_t s;
 
@@ -262,14 +263,14 @@ unsigned char *OPENSSL_hexstr2buf(const char *str, long *len)
             OPENSSL_free(hexbuf);
             return NULL;
         }
-        cl = OPENSSL_hexchar2int(cl);
-        ch = OPENSSL_hexchar2int(ch);
-        if (cl < 0 || ch < 0) {
+        cli = OPENSSL_hexchar2int(cl);
+        chi = OPENSSL_hexchar2int(ch);
+        if (cli < 0 || chi < 0) {
             OPENSSL_free(hexbuf);
             CRYPTOerr(CRYPTO_F_OPENSSL_HEXSTR2BUF, CRYPTO_R_ILLEGAL_HEX_DIGIT);
             return NULL;
         }
-        *q++ = (ch << 4) | cl;
+        *q++ = (unsigned char)((chi << 4) | cli);
     }
 
     if (len)