compare literal values if times are not well-formed for semantic comparison
diff --git a/skeletons/GeneralizedTime.c b/skeletons/GeneralizedTime.c
index 02d79a7..365ef19 100644
--- a/skeletons/GeneralizedTime.c
+++ b/skeletons/GeneralizedTime.c
@@ -766,8 +766,28 @@
     if(a && b) {
         int afrac_value, afrac_digits;
         int bfrac_value, bfrac_digits;
-        time_t at = asn_GT2time_frac(a, &afrac_value, &afrac_digits, 0, 0);
-        time_t bt = asn_GT2time_frac(b, &bfrac_value, &bfrac_digits, 0, 0);
+        int aerr, berr;
+        time_t at, bt;
+
+        errno = EPERM;
+        at = asn_GT2time_frac(a, &afrac_value, &afrac_digits, 0, 0);
+        aerr = errno;
+        errno = EPERM;
+        bt = asn_GT2time_frac(b, &bfrac_value, &bfrac_digits, 0, 0);
+        berr = errno;
+
+        if(at == -1 && aerr != EPERM) {
+            if(bt == -1 && berr != EPERM) {
+                return OCTET_STRING_compare(td, aptr, bptr);
+            } else {
+                return -1;
+            }
+        } else if(bt == -1 && berr != EPERM) {
+            return 1;
+        } else {
+            /* Both values are valid. */
+        }
+
         if(at < bt) {
             return -1;
         } else if(at > bt) {
diff --git a/skeletons/UTCTime.c b/skeletons/UTCTime.c
index 8ff9d92..d645869 100644
--- a/skeletons/UTCTime.c
+++ b/skeletons/UTCTime.c
@@ -235,8 +235,28 @@
     (void)td;
 
     if(a && b) {
-        time_t at = asn_UT2time(a, 0, 0);
-        time_t bt = asn_UT2time(b, 0, 0);
+        time_t at, bt;
+        int aerr, berr;
+
+        errno = EPERM;
+        at = asn_UT2time(a, 0, 0);
+        aerr = errno;
+        errno = EPERM;
+        bt = asn_UT2time(b, 0, 0);
+        berr = errno;
+
+        if(at == -1 && aerr != EPERM) {
+            if(bt == -1 && berr != EPERM) {
+                return OCTET_STRING_compare(td, aptr, bptr);
+            } else {
+                return -1;
+            }
+        } else if(bt == -1 && berr != EPERM) {
+            return 1;
+        } else {
+            /* Both values are valid. */
+        }
+
         if(at < bt) {
             return -1;
         } else if(at > bt) {