fixed 64 bit issue with print time

This commit is contained in:
Andreas Steffen 2007-01-20 15:13:05 +00:00
parent 4305c488ed
commit 2f5914a343
5 changed files with 39 additions and 24 deletions

View File

@ -440,22 +440,22 @@ static int print(FILE *stream, const struct printf_info *info,
now = time(NULL); now = time(NULL);
written += fprintf(stream, "%#T, revoked certs: %d\n", this->installed, utc, written += fprintf(stream, "%#T, revoked certs: %d\n", &this->installed, utc,
this->revokedCertificates->get_count(this->revokedCertificates)); this->revokedCertificates->get_count(this->revokedCertificates));
written += fprintf(stream, " issuer: '%D'\n", this->issuer); written += fprintf(stream, " issuer: '%D'\n", this->issuer);
written += fprintf(stream, " updates: this %#T\n", this->thisUpdate, utc); written += fprintf(stream, " updates: this %#T\n", &this->thisUpdate, utc);
written += fprintf(stream, " next %#T ", this->nextUpdate, utc); written += fprintf(stream, " next %#T ", &this->nextUpdate, utc);
if (this->nextUpdate == UNDEFINED_TIME) if (this->nextUpdate == UNDEFINED_TIME)
{ {
written += fprintf(stream, "ok (expires never)"); written += fprintf(stream, "ok (expires never)");
} }
else if (now > this->nextUpdate) else if (now > this->nextUpdate)
{ {
written += fprintf(stream, "expired (since %V)", now, this->nextUpdate); written += fprintf(stream, "expired (since %V)", &now, &this->nextUpdate);
} }
else if (now > this->nextUpdate - CRL_WARNING_INTERVAL * 60 * 60 * 24) else if (now > this->nextUpdate - CRL_WARNING_INTERVAL * 60 * 60 * 24)
{ {
written += fprintf(stream, "ok (expires in %V)", now, this->nextUpdate); written += fprintf(stream, "ok (expires in %V)", &now, &this->nextUpdate);
} }
else else
{ {

View File

@ -1068,7 +1068,7 @@ static int print(FILE *stream, const struct printf_info *info,
/* determine the current time */ /* determine the current time */
time_t now = time(NULL); time_t now = time(NULL);
written += fprintf(stream, "%#T\n", this->installed, utc); written += fprintf(stream, "%#T\n", &this->installed, utc);
if (this->subjectAltNames->get_count(this->subjectAltNames)) if (this->subjectAltNames->get_count(this->subjectAltNames))
{ {
@ -1095,27 +1095,27 @@ static int print(FILE *stream, const struct printf_info *info,
written += fprintf(stream, " subject: '%D'\n", this->subject); written += fprintf(stream, " subject: '%D'\n", this->subject);
written += fprintf(stream, " issuer: '%D'\n", this->issuer); written += fprintf(stream, " issuer: '%D'\n", this->issuer);
written += fprintf(stream, " serial: %#B\n", &this->serialNumber); written += fprintf(stream, " serial: %#B\n", &this->serialNumber);
written += fprintf(stream, " validity: not before %#T, ", this->notBefore, utc); written += fprintf(stream, " validity: not before %#T, ", &this->notBefore, utc);
if (now < this->notBefore) if (now < this->notBefore)
{ {
written += fprintf(stream, "not valid yet (valid in %V)\n", now, this->notBefore); written += fprintf(stream, "not valid yet (valid in %V)\n", &now, &this->notBefore);
} }
else else
{ {
written += fprintf(stream, "ok\n"); written += fprintf(stream, "ok\n");
} }
written += fprintf(stream, " not after %#T, ", this->notAfter, utc); written += fprintf(stream, " not after %#T, ", &this->notAfter, utc);
if (now > this->notAfter) if (now > this->notAfter)
{ {
written += fprintf(stream, "expired (since %V)\n", now, this->notAfter); written += fprintf(stream, "expired (since %V)\n", &now, &this->notAfter);
} }
else else
{ {
written += fprintf(stream, "ok"); written += fprintf(stream, "ok");
if (now > this->notAfter - CERT_WARNING_INTERVAL * 60 * 60 * 24) if (now > this->notAfter - CERT_WARNING_INTERVAL * 60 * 60 * 24)
{ {
written += fprintf(stream, " (expires in %V)", now, this->notAfter); written += fprintf(stream, " (expires in %V)", &now, &this->notAfter);
} }
written += fprintf(stream, " \n"); written += fprintf(stream, " \n");
} }
@ -1146,10 +1146,10 @@ static int print(FILE *stream, const struct printf_info *info,
switch (this->status) switch (this->status)
{ {
case CERT_GOOD: case CERT_GOOD:
written += fprintf(stream, " until %#T", this->until, utc); written += fprintf(stream, " until %#T", &this->until, utc);
break; break;
case CERT_REVOKED: case CERT_REVOKED:
written += fprintf(stream, " on %#T", this->until, utc); written += fprintf(stream, " on %#T", &this->until, utc);
break; break;
case CERT_UNKNOWN: case CERT_UNKNOWN:
case CERT_UNDEFINED: case CERT_UNDEFINED:

View File

@ -105,7 +105,7 @@ static int print_time(FILE *stream, const struct printf_info *info,
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}; };
time_t time = *((time_t*)(args[0])); time_t *time = *((time_t**)(args[0]));
bool utc = TRUE; bool utc = TRUE;
struct tm t; struct tm t;
@ -120,11 +120,11 @@ static int print_time(FILE *stream, const struct printf_info *info,
} }
if (utc) if (utc)
{ {
gmtime_r(&time, &t); gmtime_r(time, &t);
} }
else else
{ {
localtime_r(&time, &t); localtime_r(time, &t);
} }
return fprintf(stream, "%s %02d %02d:%02d:%02d%s%04d", return fprintf(stream, "%s %02d %02d:%02d:%02d%s%04d",
months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min, months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min,
@ -137,11 +137,12 @@ static int print_time(FILE *stream, const struct printf_info *info,
static int print_time_delta(FILE *stream, const struct printf_info *info, static int print_time_delta(FILE *stream, const struct printf_info *info,
const void *const *args) const void *const *args)
{ {
time_t start = *((time_t*)(args[0])); time_t *start = *((time_t**)(args[0]));
time_t end = *((time_t*)(args[1])); time_t *end = *((time_t**)(args[1]));
u_int delta = abs(end - start); u_int delta = abs(*end - *start);
char* unit = "second"; char* unit = "second";
if (delta > 2 * 60 * 60 * 24) if (delta > 2 * 60 * 60 * 24)
{ {
delta /= 60 * 60 * 24; delta /= 60 * 60 * 24;
@ -165,6 +166,6 @@ static int print_time_delta(FILE *stream, const struct printf_info *info,
*/ */
static void __attribute__ ((constructor))print_register() static void __attribute__ ((constructor))print_register()
{ {
register_printf_function(PRINTF_TIME, print_time, arginfo_int_alt_int_int); register_printf_function(PRINTF_TIME, print_time, arginfo_ptr_alt_ptr_int);
register_printf_function(PRINTF_TIME_DELTA, print_time_delta, arginfo_int_int); register_printf_function(PRINTF_TIME_DELTA, print_time_delta, arginfo_ptr_ptr);
} }

View File

@ -34,6 +34,19 @@ int arginfo_ptr(const struct printf_info *info, size_t n, int *argtypes)
return 1; return 1;
} }
/**
* arginfo handler for two prt arguments
*/
int arginfo_ptr_ptr(const struct printf_info *info, size_t n, int *argtypes)
{
if (n > 1)
{
argtypes[0] = PA_POINTER;
argtypes[1] = PA_POINTER;
}
return 2;
}
/** /**
* arginfo handler for one ptr, one int * arginfo handler for one ptr, one int
*/ */

View File

@ -36,9 +36,9 @@
#define PRINTF_CHUNK 'B' #define PRINTF_CHUNK 'B'
/** 2 arguments: u_char *buffer, int size */ /** 2 arguments: u_char *buffer, int size */
#define PRINTF_BYTES 'b' #define PRINTF_BYTES 'b'
/** 1 argument: int time; with #-modifier 2 arguments: int time, bool utc */ /** 1 argument: time_t *time; with #-modifier 2 arguments: time_t *time, bool utc */
#define PRINTF_TIME 'T' #define PRINTF_TIME 'T'
/** 2 arguments: integer begin, int end */ /** 2 arguments: time_t *begin, time_t *end */
#define PRINTF_TIME_DELTA 'V' #define PRINTF_TIME_DELTA 'V'
/** 1 argument: x509_t *cert; with #-modifier 2 arguments: x509_t *cert, bool utc */ /** 1 argument: x509_t *cert; with #-modifier 2 arguments: x509_t *cert, bool utc */
#define PRINTF_X509 'Q' #define PRINTF_X509 'Q'
@ -63,6 +63,7 @@
* Generic arginfo handlers for printf() hooks * Generic arginfo handlers for printf() hooks
*/ */
int arginfo_ptr(const struct printf_info *info, size_t n, int *argtypes); int arginfo_ptr(const struct printf_info *info, size_t n, int *argtypes);
int arginfo_ptr_ptr(const struct printf_info *info, size_t n, int *argtypes);
int arginfo_ptr_int(const struct printf_info *info, size_t n, int *argtypes); int arginfo_ptr_int(const struct printf_info *info, size_t n, int *argtypes);
int arginfo_int_int(const struct printf_info *info, size_t n, int *argtypes); int arginfo_int_int(const struct printf_info *info, size_t n, int *argtypes);
int arginfo_ptr_alt_ptr_int(const struct printf_info *info, size_t n, int *argtypes); int arginfo_ptr_alt_ptr_int(const struct printf_info *info, size_t n, int *argtypes);