summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2004-04-24 22:38:30 +0000
committerKen Raeburn <raeburn@mit.edu>2004-04-24 22:38:30 +0000
commit17c8862153e4602dabdc21d622e2301477e79605 (patch)
tree6b2bfcfe4660a2f867c825842ef3a3328f234206 /src
parent3c51a8b0615193d36cff2de1af7c70d982dfaf66 (diff)
downloadkrb5-17c8862153e4602dabdc21d622e2301477e79605.tar.gz
krb5-17c8862153e4602dabdc21d622e2301477e79605.tar.xz
krb5-17c8862153e4602dabdc21d622e2301477e79605.zip
Handle the somewhat common fixed case of time value 0 more efficiently
* asn1_decode.c (asn1_decode_generaltime): If the input string is the magic UNIX time zero, bypass all the arithmetic and return 0. * asn1_encode.c (asn1_encode_generaltime): If the input time value is the UNIX epoch, use a hardcoded string instead of doing the math. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16272 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/lib/krb5/asn.1/ChangeLog8
-rw-r--r--src/lib/krb5/asn.1/asn1_decode.c5
-rw-r--r--src/lib/krb5/asn.1/asn1_encode.c39
3 files changed, 36 insertions, 16 deletions
diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog
index 520999d7fc..b8b4d1025e 100644
--- a/src/lib/krb5/asn.1/ChangeLog
+++ b/src/lib/krb5/asn.1/ChangeLog
@@ -1,3 +1,11 @@
+2004-04-24 Ken Raeburn <raeburn@mit.edu>
+
+ * asn1_decode.c (asn1_decode_generaltime): If the input string is
+ the magic UNIX time zero, bypass all the arithmetic and return 0.
+ * asn1_encode.c (asn1_encode_generaltime): If the input time
+ value is the UNIX epoch, use a hardcoded string instead of doing
+ the math.
+
2003-10-08 Tom Yu <tlyu@mit.edu>
* asn1_k_encode.c (asn1_encode_krb_saved_safe_body): New function;
diff --git a/src/lib/krb5/asn.1/asn1_decode.c b/src/lib/krb5/asn.1/asn1_decode.c
index 65863202aa..60ae08802d 100644
--- a/src/lib/krb5/asn.1/asn1_decode.c
+++ b/src/lib/krb5/asn.1/asn1_decode.c
@@ -236,6 +236,10 @@ asn1_error_code asn1_decode_generaltime(asn1buf *buf, time_t *val)
free(s);
return ASN1_BAD_FORMAT;
}
+ if(s[0] == '1' && !memcmp("19700101000000Z", s, 15)) {
+ t = 0;
+ goto done;
+ }
#define c2i(c) ((c)-'0')
ts.tm_year = 1000*c2i(s[0]) + 100*c2i(s[1]) + 10*c2i(s[2]) + c2i(s[3])
- 1900;
@@ -250,6 +254,7 @@ asn1_error_code asn1_decode_generaltime(asn1buf *buf, time_t *val)
if(t == -1) return ASN1_BAD_TIMEFORMAT;
+done:
*val = t;
cleanup();
}
diff --git a/src/lib/krb5/asn.1/asn1_encode.c b/src/lib/krb5/asn.1/asn1_encode.c
index 6bd40dfe7b..df3c4ec713 100644
--- a/src/lib/krb5/asn.1/asn1_encode.c
+++ b/src/lib/krb5/asn.1/asn1_encode.c
@@ -226,28 +226,35 @@ asn1_error_code asn1_encode_generaltime(asn1buf *buf, time_t val,
{
asn1_error_code retval;
struct tm *gtime;
- char s[16];
+ char s[16], *sp;
unsigned int length, sum=0;
time_t gmt_time = val;
- gtime = gmtime(&gmt_time);
-
/*
* Time encoding: YYYYMMDDhhmmssZ
- *
- * Sanity check this just to be paranoid, as gmtime can return NULL,
- * and some bogus implementations might overrun on the sprintf.
*/
- if (gtime == NULL ||
- gtime->tm_year > 8099 || gtime->tm_mon > 11 ||
- gtime->tm_mday > 31 || gtime->tm_hour > 23 ||
- gtime->tm_min > 59 || gtime->tm_sec > 59)
- return ASN1_BAD_GMTIME;
- sprintf(s, "%04d%02d%02d%02d%02d%02dZ",
- 1900+gtime->tm_year, gtime->tm_mon+1, gtime->tm_mday,
- gtime->tm_hour, gtime->tm_min, gtime->tm_sec);
-
- retval = asn1buf_insert_charstring(buf,15,s);
+ if (gmt_time == 0) {
+ sp = "19700101000000Z";
+ } else {
+
+ /*
+ * Sanity check this just to be paranoid, as gmtime can return NULL,
+ * and some bogus implementations might overrun on the sprintf.
+ */
+ gtime = gmtime(&gmt_time);
+
+ if (gtime == NULL ||
+ gtime->tm_year > 8099 || gtime->tm_mon > 11 ||
+ gtime->tm_mday > 31 || gtime->tm_hour > 23 ||
+ gtime->tm_min > 59 || gtime->tm_sec > 59)
+ return ASN1_BAD_GMTIME;
+ sprintf(s, "%04d%02d%02d%02d%02d%02dZ",
+ 1900+gtime->tm_year, gtime->tm_mon+1, gtime->tm_mday,
+ gtime->tm_hour, gtime->tm_min, gtime->tm_sec);
+ sp = s;
+ }
+
+ retval = asn1buf_insert_charstring(buf,15,sp);
if(retval) return retval;
sum = 15;