Branch: Tag:

2002-10-03

2002-10-03 16:04:56 by Martin Stjernholm <mast@lysator.liu.se>

Fixed missing checks for NULL from gmtime(2), localtime(2) and ctime(2)
which could cause segfaults. E.g. on NT they don't handle negative time
stamps.

Rev: src/builtin.cmod:1.91
Rev: src/modules/HTTPLoop/log.c:1.11
Rev: src/modules/Oracle/oracle.c:1.71
Rev: src/modules/spider/discdate.c:1.11

1:   /* -*- c -*- -  * $Id: builtin.cmod,v 1.90 2002/08/15 14:49:19 marcus Exp $ +  * $Id: builtin.cmod,v 1.91 2002/10/03 16:04:56 mast Exp $    */      #include "global.h"
340:    *! Convert the output from a previous call to @[time()] into a readable    *! string containing the current year, month, day and time.    *! +  *! Like @[localtime], this function might return zero if the ctime(2) +  *! call failed on the system. It's platform dependent what time +  *! ranges that function can handle, e.g. Windows doesn't handle a +  *! negative @[timestamp]. +  *!    *! @seealso    *! @[time()], @[localtime()], @[mktime()], @[gmtime()]    */
348:    optflags OPT_TRY_OPTIMIZE;   {    time_t i=(time_t)timestamp; -  RETURN make_shared_string(ctime(&i)); +  char *s = ctime (&i); +  if (!s) { +  pop_stack(); +  push_int (0); +  return;    } -  +  RETURN make_shared_string(s); + }      /*! @decl mapping mkmapping(array ind, array val)    *!