[openssl-commits] [openssl] master update

Rich Salz rsalz at openssl.org
Wed Apr 29 18:16:10 UTC 2015


The branch master has been updated
       via  2fa45e6ee722078bc55311c66bdba1ca2fc69c28 (commit)
      from  ecf3a1fb181c08540342cceb6549e0408b32d135 (commit)


- Log -----------------------------------------------------------------
commit 2fa45e6ee722078bc55311c66bdba1ca2fc69c28
Author: Rich Salz <rsalz at openssl.org>
Date:   Wed Apr 29 14:15:50 2015 -0400

    use isxdigit and apps_tohex
    
    Replace ad-hoc ascii->hex with isxdigit and new app_tohex.
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>

-----------------------------------------------------------------------

Summary of changes:
 apps/apps.c | 39 +++++++++++++++++++++++++++++++++++++++
 apps/apps.h |  1 +
 apps/ca.c   | 11 ++++-------
 apps/enc.c  |  9 ++-------
 4 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/apps/apps.c b/apps/apps.c
index a4eecae..bec10a2 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -2673,6 +2673,45 @@ int app_access(const char* name, int flag)
 #endif
 }
 
+int app_hex(char c)
+{
+    switch (c) {
+    default:
+    case '0':
+        return 0;
+    case '1':
+        return 1;
+    case '2':
+        return 2;
+    case '3':
+        return 3;
+    case '4':
+          return 4;
+    case '5':
+          return 5;
+    case '6':
+          return 6;
+    case '7':
+          return 7;
+    case '8':
+          return 8;
+    case '9':
+          return 9;
+    case 'a': case 'A':
+          return 0x0A;
+    case 'b': case 'B':
+          return 0x0B;
+    case 'c': case 'C':
+          return 0x0C;
+    case 'd': case 'D':
+          return 0x0D;
+    case 'e': case 'E':
+          return 0x0E;
+    case 'f': case 'F':
+          return 0x0F;
+    }
+}
+
 /* app_isdir section */
 #ifdef _WIN32
 int app_isdir(const char *name)
diff --git a/apps/apps.h b/apps/apps.h
index db67957..1ba6485 100644
--- a/apps/apps.h
+++ b/apps/apps.h
@@ -544,6 +544,7 @@ void store_setup_crl_download(X509_STORE *st);
 
 # define SERIAL_RAND_BITS        64
 
+int app_hex(char);
 int app_isdir(const char *);
 int app_access(const char *, int flag);
 int raw_read_stdin(void *, int);
diff --git a/apps/ca.c b/apps/ca.c
index ba666ee..9c96417 100644
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -778,16 +778,13 @@ end_of_options:
                        i + 1, j);
             goto end;
         }
-        while (*p) {
-            if (!(((*p >= '0') && (*p <= '9')) ||
-                  ((*p >= 'A') && (*p <= 'F')) ||
-                  ((*p >= 'a') && (*p <= 'f')))) {
+        for ( ; *p; p++) {
+            if (!isxdigit(*p)) {
                 BIO_printf(bio_err,
-                           "entry %d: bad serial number characters, char pos %ld, char is '%c'\n",
-                           i + 1, (long)(p - pp[DB_serial]), *p);
+                           "entry %d: bad char 0%o '%c' in serial number\n",
+                           i + 1, *p, *p);
                 goto end;
             }
-            p++;
         }
     }
     if (verbose) {
diff --git a/apps/enc.c b/apps/enc.c
index 794fce1..c6b8d2b 100644
--- a/apps/enc.c
+++ b/apps/enc.c
@@ -617,16 +617,11 @@ static int set_hex(char *in, unsigned char *out, int size)
         *(in++) = '\0';
         if (j == 0)
             break;
-        if ((j >= '0') && (j <= '9'))
-            j -= '0';
-        else if ((j >= 'A') && (j <= 'F'))
-            j = j - 'A' + 10;
-        else if ((j >= 'a') && (j <= 'f'))
-            j = j - 'a' + 10;
-        else {
+        if (!isxdigit(j)) {
             BIO_printf(bio_err, "non-hex digit\n");
             return (0);
         }
+        j = (unsigned char)app_hex(j);
         if (i & 1)
             out[i / 2] |= j;
         else


More information about the openssl-commits mailing list