[openssl-commits] [openssl] master update

Rich Salz rsalz at openssl.org
Wed Aug 30 15:43:31 UTC 2017


The branch master has been updated
       via  e44d37618018eb5dc8ba2d776b215abdaca6090a (commit)
      from  54cf3b981afcbbd3754c8ba1114ab6a658d86c08 (commit)


- Log -----------------------------------------------------------------
commit e44d37618018eb5dc8ba2d776b215abdaca6090a
Author: Todd Short <tshort at akamai.com>
Date:   Fri Aug 25 16:34:56 2017 -0400

    Fix return value of ASN1_TIME_compare
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4264)

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

Summary of changes:
 crypto/asn1/a_time.c  |  2 +-
 test/asn1_time_test.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c
index cb19e80..1babb96 100644
--- a/crypto/asn1/a_time.c
+++ b/crypto/asn1/a_time.c
@@ -543,7 +543,7 @@ int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b)
 {
     int day, sec;
 
-    if (!ASN1_TIME_diff(&day, &sec, a, b))
+    if (!ASN1_TIME_diff(&day, &sec, b, a))
         return -2;
     if (day > 0 || sec > 0)
         return 1;
diff --git a/test/asn1_time_test.c b/test/asn1_time_test.c
index 96394a1..874260e 100644
--- a/test/asn1_time_test.c
+++ b/test/asn1_time_test.c
@@ -274,6 +274,51 @@ static int test_table_neg_64bit(int idx)
     return test_table(tbl_testdata_neg_64bit, idx);
 }
 
+struct compare_testdata {
+    ASN1_TIME t1;
+    ASN1_TIME t2;
+    int result;
+};
+
+static unsigned char TODAY_GEN_STR[] = "20170825000000Z";
+static unsigned char TOMORROW_GEN_STR[] = "20170826000000Z";
+static unsigned char TODAY_UTC_STR[] = "170825000000Z";
+static unsigned char TOMORROW_UTC_STR[] = "170826000000Z";
+
+#define TODAY_GEN    { sizeof(TODAY_GEN_STR)-1, V_ASN1_GENERALIZEDTIME, TODAY_GEN_STR, 0 }
+#define TOMORROW_GEN { sizeof(TOMORROW_GEN_STR)-1, V_ASN1_GENERALIZEDTIME, TOMORROW_GEN_STR, 0 }
+#define TODAY_UTC    { sizeof(TODAY_UTC_STR)-1, V_ASN1_UTCTIME, TODAY_UTC_STR, 0 }
+#define TOMORROW_UTC { sizeof(TOMORROW_UTC_STR)-1, V_ASN1_UTCTIME, TOMORROW_UTC_STR, 0 }
+
+static struct compare_testdata tbl_compare_testdata[] = {
+    { TODAY_GEN,    TODAY_GEN,     0 },
+    { TODAY_GEN,    TODAY_UTC,     0 },
+    { TODAY_GEN,    TOMORROW_GEN, -1 },
+    { TODAY_GEN,    TOMORROW_UTC, -1 },
+
+    { TODAY_UTC,    TODAY_GEN,     0 },
+    { TODAY_UTC,    TODAY_UTC,     0 },
+    { TODAY_UTC,    TOMORROW_GEN, -1 },
+    { TODAY_UTC,    TOMORROW_UTC, -1 },
+
+    { TOMORROW_GEN, TODAY_GEN,     1 },
+    { TOMORROW_GEN, TODAY_UTC,     1 },
+    { TOMORROW_GEN, TOMORROW_GEN,  0 },
+    { TOMORROW_GEN, TOMORROW_UTC,  0 },
+
+    { TOMORROW_UTC, TODAY_GEN,     1 },
+    { TOMORROW_UTC, TODAY_UTC,     1 },
+    { TOMORROW_UTC, TOMORROW_GEN,  0 },
+    { TOMORROW_UTC, TOMORROW_UTC,  0 }
+};
+
+static int test_table_compare(int idx)
+{
+    struct compare_testdata *td = &tbl_compare_testdata[idx];
+
+    return TEST_int_eq(ASN1_TIME_compare(&td->t1, &td->t2), td->result);
+}
+
 int setup_tests(void)
 {
     /*
@@ -305,5 +350,6 @@ int setup_tests(void)
             ADD_ALL_TESTS(test_table_neg_64bit, OSSL_NELEM(tbl_testdata_neg_64bit));
         }
     }
+    ADD_ALL_TESTS(test_table_compare, OSSL_NELEM(tbl_compare_testdata));
     return 1;
 }


More information about the openssl-commits mailing list