Bug 46193 - [BTLS] MonoBtlsX509.NotAfter problem on i386
Summary: [BTLS] MonoBtlsX509.NotAfter problem on i386
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-31 17:41 UTC by Martin Baulig
Modified: 2016-11-07 19:03 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Stand-alone test case (49.26 KB, application/octet-stream)
2016-10-31 17:41 UTC, Martin Baulig
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Martin Baulig 2016-10-31 17:41:09 UTC
Apply this PR:
https://github.com/mono/mono/pull/3857

then do
$ export MONO_TLS_PROVIDER=btls
$ cd mcs/class/System
$ make check
Comment 1 Martin Baulig 2016-10-31 17:41:59 UTC
Created attachment 18277 [details]
Stand-alone test case
Comment 2 Martin Baulig 2016-10-31 17:42:30 UTC
Run with lldb and set a breakpoint in mono_btls_util_asn1_time_to_ticks().
Comment 3 Martin Baulig 2016-10-31 17:42:58 UTC
Using mono-4.8.0-branch on OS X / 64-bit:

=====
(lldb) r
Process 32320 launched: '/Workspace/STABLE/bin/mono' (x86_64)
Process 32320 stopped
* thread #1: tid = 0x14e62fc, 0x00000001002211f0 mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 16 at btls-util.c:33, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001002211f0 mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 16 at btls-util.c:33
   30  		struct tm tm;
   31  		time_t epoch;
   32  	
-> 33  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
   34  		asn1_generalizedtime_to_tm (&tm, gtime);
   35  		ASN1_GENERALIZEDTIME_free (gtime);
   36  		epoch = timegm(&tm);
(lldb) p time
(ASN1_TIME *) $0 = 0x0000000100957700
(lldb) n
Process 32320 stopped
* thread #1: tid = 0x14e62fc, 0x0000000100221201 mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 33 at btls-util.c:34, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x0000000100221201 mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 33 at btls-util.c:34
   31  		time_t epoch;
   32  	
   33  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
-> 34  		asn1_generalizedtime_to_tm (&tm, gtime);
   35  		ASN1_GENERALIZEDTIME_free (gtime);
   36  		epoch = timegm(&tm);
   37  	
(lldb) p gtime
(ASN1_GENERALIZEDTIME *) $2 = 0x0000000100983880
(lldb) p *gtime
(ASN1_GENERALIZEDTIME) $3 = (length = 15, type = 24, data = "20391231235959Z", flags = 0)
(lldb) n
Process 32320 stopped
* thread #1: tid = 0x14e62fc, 0x000000010022120a mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 42 at btls-util.c:35, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = step over
Return value: (int) $4 = 1

    frame #0: 0x000000010022120a mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 42 at btls-util.c:35
   32  	
   33  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
   34  		asn1_generalizedtime_to_tm (&tm, gtime);
-> 35  		ASN1_GENERALIZEDTIME_free (gtime);
   36  		epoch = timegm(&tm);
   37  	
   38  		return epoch;
(lldb) p tm
(tm) $5 = {
  tm_sec = 59
  tm_min = 59
  tm_hour = 23
  tm_mday = 31
  tm_mon = 11
  tm_year = 139
  tm_wday = 762971409
  tm_yday = 699254877
  tm_isdst = 7274573
  tm_gmtoff = 30118166112960620
  tm_zone = 0x79e78d99798808bf <no value available>
}
(lldb) n
Process 32320 stopped
* thread #1: tid = 0x14e62fc, 0x000000010022121a mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 58 at btls-util.c:36, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010022121a mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 58 at btls-util.c:36
   33  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
   34  		asn1_generalizedtime_to_tm (&tm, gtime);
   35  		ASN1_GENERALIZEDTIME_free (gtime);
-> 36  		epoch = timegm(&tm);
   37  	
   38  		return epoch;
   39  	}
(lldb) n
Process 32320 stopped
* thread #1: tid = 0x14e62fc, 0x0000000100221223 mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 67 at btls-util.c:38, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x0000000100221223 mono`mono_btls_util_asn1_time_to_ticks(time=0x0000000100957700) + 67 at btls-util.c:38
   35  		ASN1_GENERALIZEDTIME_free (gtime);
   36  		epoch = timegm(&tm);
   37  	
-> 38  		return epoch;
   39  	}
   40  	
   41  	// Copied from crypto/bio/printf.c, takes va_list
(lldb) p epoch
(time_t) $6 = 2208988799
(lldb) 
[1]+  Stopped                 lldb -- /Workspace/STABLE/bin/mono --debug ./bin/Debug/TestCertificates.exe
[TEST:TestCertificates]$ touch log


=====
Comment 4 Martin Baulig 2016-10-31 17:43:56 UTC
With this PR and running on OS X / i386:

====
[TEST:TestCertificates]$ lldb -- /Workspace/TEST/bin/mono --debug ./bin/Debug/TestCertificates.exe
(lldb) target create "/Workspace/TEST/bin/mono"
Current executable set to '/Workspace/TEST/bin/mono' (i386).
(lldb) settings set -- target.run-args  "--debug" "./bin/Debug/TestCertificates.exe"
(lldb) mono_btls_util_asn1_time_to_ticks
error: 'mono_btls_util_asn1_time_to_ticks' is not a valid command.
error: Unrecognized command 'mono_btls_util_asn1_time_to_ticks'.
(lldb) b mono_btls_util_asn1_time_to_ticks
Breakpoint 1: where = mono`mono_btls_util_asn1_time_to_ticks + 23 at btls-util.c:34, address = 0x003abfb7
(lldb) r
Process 52049 launched: '/Workspace/TEST/bin/mono' (i386)
Process 52049 stopped
* thread #1: tid = 0x14f91ff, 0x003abfb7 mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 23 at btls-util.c:34, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x003abfb7 mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 23 at btls-util.c:34
   31  		time_t epoch;
   32  		int ret;
   33  		
-> 34  		memset (&tm, 0, sizeof (tm));
   35  	
   36  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
   37  		ret = asn1_generalizedtime_to_tm (&tm, gtime);
(lldb) n
Process 52049 stopped
* thread #1: tid = 0x14f91ff, 0x003abfd5 mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 53 at btls-util.c:36, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x003abfd5 mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 53 at btls-util.c:36
   33  		
   34  		memset (&tm, 0, sizeof (tm));
   35  	
-> 36  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
   37  		ret = asn1_generalizedtime_to_tm (&tm, gtime);
   38  		ASN1_GENERALIZEDTIME_free (gtime);
   39  		epoch = timegm(&tm);
(lldb) 
Process 52049 stopped
* thread #1: tid = 0x14f91ff, 0x003abfee mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 78 at btls-util.c:37, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x003abfee mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 78 at btls-util.c:37
   34  		memset (&tm, 0, sizeof (tm));
   35  	
   36  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
-> 37  		ret = asn1_generalizedtime_to_tm (&tm, gtime);
   38  		ASN1_GENERALIZEDTIME_free (gtime);
   39  		epoch = timegm(&tm);
   40  		epoch = mktime(&tm);
(lldb) p gmtime
error: 'gmtime' has unknown type; cast it to its declared type to use it
(lldb) p *gtime
(ASN1_GENERALIZEDTIME) $1 = (length = 15, type = 24, data = "20391231235959Z", flags = 0)
(lldb) n
Process 52049 stopped
* thread #1: tid = 0x14f91ff, 0x003ac000 mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 96 at btls-util.c:38, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x003ac000 mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 96 at btls-util.c:38
   35  	
   36  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
   37  		ret = asn1_generalizedtime_to_tm (&tm, gtime);
-> 38  		ASN1_GENERALIZEDTIME_free (gtime);
   39  		epoch = timegm(&tm);
   40  		epoch = mktime(&tm);
   41  	
(lldb) p ret
(int) $3 = 1
(lldb) p tm
(tm) $4 = {
  tm_sec = 59
  tm_min = 59
  tm_hour = 23
  tm_mday = 31
  tm_mon = 11
  tm_year = 139
  tm_wday = 0
  tm_yday = 0
  tm_isdst = 0
  tm_gmtoff = 0
  tm_zone = 0x00000000 <no value available>
}
(lldb) n
Process 52049 stopped
* thread #1: tid = 0x14f91ff, 0x003ac00e mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 110 at btls-util.c:39, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x003ac00e mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 110 at btls-util.c:39
   36  		gtime = ASN1_TIME_to_generalizedtime (time, NULL);
   37  		ret = asn1_generalizedtime_to_tm (&tm, gtime);
   38  		ASN1_GENERALIZEDTIME_free (gtime);
-> 39  		epoch = timegm(&tm);
   40  		epoch = mktime(&tm);
   41  	
   42  		return epoch;
(lldb) p tm
(tm) $5 = {
  tm_sec = 59
  tm_min = 59
  tm_hour = 23
  tm_mday = 31
  tm_mon = 11
  tm_year = 139
  tm_wday = 0
  tm_yday = 0
  tm_isdst = 0
  tm_gmtoff = 0
  tm_zone = 0x00000000 <no value available>
}
(lldb) n
Process 52049 stopped
* thread #1: tid = 0x14f91ff, 0x003ac01c mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 124 at btls-util.c:40, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x003ac01c mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 124 at btls-util.c:40
   37  		ret = asn1_generalizedtime_to_tm (&tm, gtime);
   38  		ASN1_GENERALIZEDTIME_free (gtime);
   39  		epoch = timegm(&tm);
-> 40  		epoch = mktime(&tm);
   41  	
   42  		return epoch;
   43  	}
(lldb) p epoch
(time_t) $6 = -1
(lldb) n
Process 52049 stopped
* thread #1: tid = 0x14f91ff, 0x003ac027 mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 135 at btls-util.c:42, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x003ac027 mono`mono_btls_util_asn1_time_to_ticks(time=0x00b20600) + 135 at btls-util.c:42
   39  		epoch = timegm(&tm);
   40  		epoch = mktime(&tm);
   41  	
-> 42  		return epoch;
   43  	}
   44  	
   45  	// Copied from crypto/bio/printf.c, takes va_list
(lldb) p epoch
(time_t) $7 = -1
(lldb) 
=====
Comment 5 Zoltan Varga 2016-10-31 20:09:15 UTC
time_t seems to be a signed 32 bit on 32 bit osx, so it might not be able to store all possible values. Are these time values occur in practice, or only in the testcase ?
Comment 7 Martin Baulig 2016-11-07 19:03:11 UTC
Fixed.