From c6a3d03dcde0df7894da8f2d63516ad149238792 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 24 Oct 2009 05:18:20 +0000 Subject: [PATCH] FIx SSL certificate date parsing to subtract 1 from the month to fit the convention of a struct tm. The bug was reported by Matt Selsky. --- nse_ssl_cert.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nse_ssl_cert.cc b/nse_ssl_cert.cc index 1417d5bc5..9e58339b2 100644 --- a/nse_ssl_cert.cc +++ b/nse_ssl_cert.cc @@ -280,6 +280,10 @@ static int time_to_tm(const ASN1_TIME *t, struct tm *result) } result->tm_mon = parse_int(p, 2); + /* struct tm uses zero-indexed months. */ + if (result->tm_mon == 0) + return -1; + result->tm_mon--; result->tm_mday = parse_int(p + 2, 2); result->tm_hour = parse_int(p + 4, 2); result->tm_min = parse_int(p + 6, 2); @@ -302,6 +306,7 @@ static void tm_to_table(lua_State *L, const struct tm *tm) lua_pushnumber(L, tm->tm_year); lua_setfield(L, -2, "year"); + /* Lua uses one-indexed months. */ lua_pushnumber(L, tm->tm_mon + 1); lua_setfield(L, -2, "month"); lua_pushnumber(L, tm->tm_mday);