Author belopolsky
Recipients AmirHabibi, abbeyj, alexandre.vassalotti, belopolsky, brett.cannon, lemburg, pitrou, srid
Date 2010-06-11.23:13:18
SpamBayes Score 0.0653851
Marked as misclassified No
Message-id <1276298000.34.0.636996134337.issue6608@psf.upfronthosting.co.za>
In-reply-to
Content
That's what CERT recommends.  Their code can be reused as is:

int validate_tm(struct tm* time) {
  /* 
   * The range of valid values of the tm_sec member is [0, 60] 
   * inclusive (to allow for leap seconds).
   */
  if (time->tm_sec < 0 || time->tm_sec > 60) return 0;
  if (time->tm_min < 0 || time->tm_min >= 60) return 0;
  if (time->tm_hour < 0 || time->tm_hour >= 24) return 0;
  if (time->tm_mday <= 0 || time->tm_mday > 31) return 0;
  if (time->tm_mon < 0 || time->tm_mon >= 12) return 0;
  /* While other years are legit, they may overflow asctime()'s buffer */
  if (time->tm_year < -999 || time->tm_year > 9999) return 0;
  if (time->tm_wday < 0 || time->tm_wday >= 7) return 0;
  if (time->tm_yday < 0 || time->tm_yday >= 366) return 0;
  return 1;
}
History
Date User Action Args
2010-06-11 23:13:20belopolskysetrecipients: + belopolsky, lemburg, brett.cannon, pitrou, alexandre.vassalotti, srid, abbeyj, AmirHabibi
2010-06-11 23:13:20belopolskysetmessageid: <1276298000.34.0.636996134337.issue6608@psf.upfronthosting.co.za>
2010-06-11 23:13:18belopolskylinkissue6608 messages
2010-06-11 23:13:18belopolskycreate