[openssl-commits] [openssl] master update

Rich Salz rsalz at openssl.org
Mon Nov 13 12:52:45 UTC 2017


The branch master has been updated
       via  4483fbae10a9277812cc8a587ef58a5a512fe7c9 (commit)
       via  1a78a33aed6d182bf26a3e839341b9ea38dbcaa3 (commit)
      from  753316232243ccbf86b96c1c51ffcb41651d9ad5 (commit)


- Log -----------------------------------------------------------------
commit 4483fbae10a9277812cc8a587ef58a5a512fe7c9
Author: FdaSilvaYY <fdasilvayy at gmail.com>
Date:   Tue Nov 7 11:50:30 2017 +0100

    Factorise duplicated code.
    
    Extract and factorise duplicated string glue code.
    Cache strlen result to avoid duplicate calls.
    [extended tests]
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4719)

commit 1a78a33aed6d182bf26a3e839341b9ea38dbcaa3
Author: FdaSilvaYY <fdasilvayy at gmail.com>
Date:   Mon Nov 6 18:32:33 2017 +0100

    remove magic number
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4719)

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

Summary of changes:
 crypto/x509v3/v3_alt.c |  3 ++-
 test/bntest.c          | 50 +++++++++++++++++++-------------------------------
 test/crltest.c         | 17 ++++-------------
 test/testutil.h        |  6 ++++++
 test/testutil/driver.c | 25 +++++++++++++++++++++++++
 5 files changed, 56 insertions(+), 45 deletions(-)

diff --git a/crypto/x509v3/v3_alt.c b/crypto/x509v3/v3_alt.c
index 520235c..832e6d1 100644
--- a/crypto/x509v3/v3_alt.c
+++ b/crypto/x509v3/v3_alt.c
@@ -68,6 +68,7 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
     unsigned char *p;
     char oline[256], htmp[5];
     int i;
+
     switch (gen->type) {
     case GEN_OTHERNAME:
         if (!X509V3_add_value("othername", "<unsupported>", &ret))
@@ -100,7 +101,7 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
         break;
 
     case GEN_DIRNAME:
-        if (X509_NAME_oneline(gen->d.dirn, oline, 256) == NULL
+        if (X509_NAME_oneline(gen->d.dirn, oline, sizeof(oline)) == NULL
                 || !X509V3_add_value("DirName", oline, &ret))
             return NULL;
         break;
diff --git a/test/bntest.c b/test/bntest.c
index 96b1638..6b7f824 100644
--- a/test/bntest.c
+++ b/test/bntest.c
@@ -80,6 +80,18 @@ static const char *findattr(STANZA *s, const char *key)
 }
 
 /*
+ * Parse BIGNUM from sparse hex-strings, return |BN_hex2bn| result.
+ */
+static int parse_bigBN(BIGNUM **out, const char *bn_strings[])
+{
+    char *bigstring = glue_strings(bn_strings, NULL);
+    int ret = BN_hex2bn(out, bigstring);
+
+    OPENSSL_free(bigstring);
+    return ret;
+}
+
+/*
  * Parse BIGNUM, return number of bytes parsed.
  */
 static int parseBN(BIGNUM **out, const char *in)
@@ -305,21 +317,6 @@ static const char *bn2strings[] = {
     NULL
 };
 
-static char *glue(const char *list[])
-{
-    size_t len = 0;
-    char *p, *save;
-    int i;
-
-    for (i = 0; list[i] != NULL; i++)
-        len += strlen(list[i]);
-    if (!TEST_ptr(p = save = OPENSSL_malloc(len + 1)))
-            return NULL;
-    for (i = 0; list[i] != NULL; i++)
-        p += strlen(strcpy(p, list[i]));
-    return save;
-}
-
 /*
  * Test constant-time modular exponentiation with 1024-bit inputs, which on
  * x86_64 cause a different code branch to be taken.
@@ -329,7 +326,6 @@ static int test_modexp_mont5(void)
     BIGNUM *a = NULL, *p = NULL, *m = NULL, *d = NULL, *e = NULL;
     BIGNUM *b = NULL, *n = NULL, *c = NULL;
     BN_MONT_CTX *mont = NULL;
-    char *bigstring;
     int st = 0;
 
     if (!TEST_ptr(a = BN_new())
@@ -375,12 +371,8 @@ static int test_modexp_mont5(void)
         goto err;
 
     /* Regression test for carry bug in sqr[x]8x_mont */
-    bigstring = glue(bn1strings);
-    BN_hex2bn(&n, bigstring);
-    OPENSSL_free(bigstring);
-    bigstring = glue(bn2strings);
-    BN_hex2bn(&a, bigstring);
-    OPENSSL_free(bigstring);
+    parse_bigBN(&n, bn1strings);
+    parse_bigBN(&a, bn2strings);
     BN_free(b);
     b = BN_dup(a);
     BN_MONT_CTX_set(mont, n, ctx);
@@ -405,7 +397,7 @@ static int test_modexp_mont5(void)
             "FCFFFFFFFFFF000000000000000000FF0302030000000000FFFFFFFFFFFFFFFF",
             "FF00FCFDFDFF030202FF00000000FFFFFFFFFFFFFFFFFF00FCFDFCFFFFFFFFFF",
             NULL
-	};
+        };
         static const char *nhex[] = {
                       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
             "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
@@ -420,14 +412,10 @@ static int test_modexp_mont5(void)
             "FFFFFFFFFFFF000000000000000000000000000000000000FFFFFFFFFFFFFFFF",
             "FFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
             NULL
-	};
-
-        bigstring = glue(ahex);
-        BN_hex2bn(&a, bigstring);
-        OPENSSL_free(bigstring);
-        bigstring = glue(nhex);
-        BN_hex2bn(&n, bigstring);
-        OPENSSL_free(bigstring);
+        };
+
+        parse_bigBN(&a, ahex);
+        parse_bigBN(&n, nhex);
     }
     BN_free(b);
     b = BN_dup(a);
diff --git a/test/crltest.c b/test/crltest.c
index b964637..4d35fd4 100644
--- a/test/crltest.c
+++ b/test/crltest.c
@@ -187,20 +187,11 @@ static X509 *test_leaf = NULL;
  * Glue an array of strings together.  Return a BIO and put the string
  * into |*out| so we can free it.
  */
-static BIO *glue(const char **pem, char **out)
+static BIO *glue2bio(const char **pem, char **out)
 {
-    char *dest;
-    int i;
     size_t s = 0;
 
-    /* Glue the strings together. */
-    for (i = 0; pem[i] != NULL; ++i)
-        s += strlen(pem[i]);
-    dest = *out = OPENSSL_malloc(s + 1);
-    if (dest == NULL)
-        return NULL;
-    for (i = 0; pem[i] != NULL; ++i)
-        dest += strlen(strcpy(dest, pem[i]));
+    *out = glue_strings(pem, &s);
     return BIO_new_mem_buf(*out, s);
 }
 
@@ -210,7 +201,7 @@ static BIO *glue(const char **pem, char **out)
 static X509_CRL *CRL_from_strings(const char **pem)
 {
     char *p;
-    BIO *b = glue(pem, &p);
+    BIO *b = glue2bio(pem, &p);
     X509_CRL *crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL);
 
     OPENSSL_free(p);
@@ -224,7 +215,7 @@ static X509_CRL *CRL_from_strings(const char **pem)
 static X509 *X509_from_strings(const char **pem)
 {
     char *p;
-    BIO *b = glue(pem, &p);
+    BIO *b = glue2bio(pem, &p);
     X509 *x = PEM_read_bio_X509(b, NULL, NULL, NULL);
 
     OPENSSL_free(p);
diff --git a/test/testutil.h b/test/testutil.h
index 8373bb8..2356786 100644
--- a/test/testutil.h
+++ b/test/testutil.h
@@ -440,4 +440,10 @@ int test_readstanza(STANZA *s);
  */
 void test_clearstanza(STANZA *s);
 
+/*
+ * Glue an array of strings together and return it as an allocated string.
+ * Optionally return the whole length of this string in |out_len|
+ */
+char *glue_strings(const char *list[], size_t *out_len);
+
 #endif                          /* HEADER_TESTUTIL_H */
diff --git a/test/testutil/driver.c b/test/testutil/driver.c
index 48593f9..9cdce7a 100644
--- a/test/testutil/driver.c
+++ b/test/testutil/driver.c
@@ -272,3 +272,28 @@ int run_tests(const char *test_prog_name)
     return EXIT_SUCCESS;
 }
 
+/*
+ * Glue an array of strings together and return it as an allocated string.
+ * Optionally return the whole length of this string in |out_len|
+ */
+char *glue_strings(const char *list[], size_t *out_len)
+{
+    size_t len = 0;
+    char *p, *ret;
+    int i;
+
+    for (i = 0; list[i] != NULL; i++)
+        len += strlen(list[i]);
+
+    if (out_len != NULL)
+        *out_len = len;
+
+    if (!TEST_ptr(ret = p = OPENSSL_malloc(len + 1)))
+        return NULL;
+
+    for (i = 0; list[i] != NULL; i++)
+        p += strlen(strcpy(p, list[i]));
+
+    return ret;
+}
+


More information about the openssl-commits mailing list