r16230: Fix Klocwork #861 and others. localtime and asctime
authorJeremy Allison <jra@samba.org>
Wed, 14 Jun 2006 21:36:49 +0000 (21:36 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:17:26 +0000 (11:17 -0500)
can return NULL. Ensure we check all returns correctly.
Jeremy.
(This used to be commit 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc)

16 files changed:
source3/auth/auth_sam.c
source3/auth/pass_check.c
source3/client/client.c
source3/client/clitar.c
source3/client/smbctool.c
source3/lib/replace.c
source3/lib/time.c
source3/nmbd/nmbd_namelistdb.c
source3/nmbd/nmbd_winsserver.c
source3/printing/lpq_parse.c
source3/smbd/lanman.c
source3/utils/net_cache.c
source3/utils/net_status.c
source3/utils/net_time.c
source3/utils/status.c
source3/web/statuspage.c

index e8018eb13ddc66b78d707f48f0f2f3e5eb48f4fa..ec405dd2be4fcd6cd6f769ba576450941b84ea51 100644 (file)
@@ -77,6 +77,7 @@ static BOOL logon_hours_ok(struct samu *sampass)
        const uint8 *hours;
        struct tm *utctime;
        time_t lasttime;
+       const char *asct;
        uint8 bitmask, bitpos;
 
        hours = pdb_get_hours(sampass);
@@ -87,6 +88,11 @@ static BOOL logon_hours_ok(struct samu *sampass)
 
        lasttime = time(NULL);
        utctime = gmtime(&lasttime);
+       if (!utctime) {
+               DEBUG(1, ("logon_hours_ok: failed to get gmtime. Failing logon for user %s\n",
+                       pdb_get_username(sampass) ));
+               return False;
+       }
 
        /* find the corresponding byte and bit */
        bitpos = (utctime->tm_wday * 24 + utctime->tm_hour) % 168;
@@ -94,15 +100,24 @@ static BOOL logon_hours_ok(struct samu *sampass)
 
        if (! (hours[bitpos/8] & bitmask)) {
                struct tm *t = localtime(&lasttime);
+               if (!t) {
+                       asct = "INVALID TIME";
+               } else {
+                       asct = asctime(t);
+                       if (!asct) {
+                               asct = "INVALID TIME";
+                       }
+               }
+               
                DEBUG(1, ("logon_hours_ok: Account for user %s not allowed to "
                          "logon at this time (%s).\n",
-                         pdb_get_username(sampass),
-                         t ? asctime(t) : "INVALID TIME"));
+                         pdb_get_username(sampass), asct ));
                return False;
        }
 
+       asct = asctime(utctime);
        DEBUG(5,("logon_hours_ok: user %s allowed to logon at this time (%s)\n",
-               pdb_get_username(sampass), asctime(utctime) ));
+               pdb_get_username(sampass), asct ? asct : "UNKNOWN TIME" ));
 
        return True;
 }
index 507e8a3836e8fd44b631772e8b25d161c3de39d9..d0a900b80f33d408be027ddea5fc7cbdb82a57ec 100644 (file)
@@ -92,6 +92,7 @@ check on a DCE/DFS authentication
 ********************************************************************/
 static BOOL dfs_auth(char *user, char *password)
 {
+       struct tm *t;
        error_status_t err;
        int err2;
        int prterr;
@@ -341,8 +342,13 @@ static BOOL dfs_auth(char *user, char *password)
        set_effective_uid(0);
        set_effective_gid(0);
 
-       DEBUG(0,
-             ("DCE context expires: %s", asctime(localtime(&expire_time))));
+       t = localtime(&expire_time);
+       if (t) {
+               const char *asct = asctime(t);
+               if (asct) {
+                       DEBUG(0,("DCE context expires: %s", asct));
+               }
+       }
 
        dcelogin_atmost_once = 1;
        return (True);
index 1fbee70645c9ecb1f34af586f5f1ac4f06b09d57..aa25d9aba5bf25da827e8aef6935103570a74167 100644 (file)
@@ -379,7 +379,7 @@ static void display_finfo(file_info *finfo)
                         finfo->name,
                         attrib_string(finfo->mode),
                         (double)finfo->size,
-                        asctime(localtime(&t)));
+                        time_to_asc(&t));
                dir_total += finfo->size;
        }
 }
@@ -2111,6 +2111,7 @@ static int cmd_stat(void)
        fstring mode_str;
        SMB_STRUCT_STAT sbuf;
        struct cli_state *targetcli;
+       struct tm *lt;
        pstring targetname;
  
        if (!SERVER_HAS_UNIX_CIFS(cli)) {
@@ -2165,13 +2166,28 @@ static int cmd_stat(void)
                (unsigned int)sbuf.st_uid, 
                (unsigned int)sbuf.st_gid);
 
-       strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_atime));
+       lt = localtime(&sbuf.st_atime);
+       if (lt) {
+               strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+       } else {
+               fstrcpy(mode_str, "unknown");
+       }
        d_printf("Access: %s\n", mode_str);
 
-       strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_mtime));
+       lt = localtime(&sbuf.st_mtime);
+       if (lt) {
+               strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+       } else {
+               fstrcpy(mode_str, "unknown");
+       }
        d_printf("Modify: %s\n", mode_str);
 
-       strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_ctime));
+       lt = localtime(&sbuf.st_ctime);
+       if (lt) {
+               strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+       } else {
+               fstrcpy(mode_str, "unknown");
+       }
        d_printf("Change: %s\n", mode_str);
        
        return 0;
@@ -2339,7 +2355,7 @@ static int cmd_newer(void)
        if (ok && (sys_stat(buf,&sbuf) == 0)) {
                newer_than = sbuf.st_mtime;
                DEBUG(1,("Getting files newer than %s",
-                        asctime(localtime(&newer_than))));
+                        time_to_asc(&newer_than)));
        } else {
                newer_than = 0;
        }
index a7bc4bfde34a2b37053d00e32a3ae3929455ff90..14c28acfc5a712302c8fe8f26c940bee9c9bd958 100644 (file)
@@ -1641,7 +1641,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind)
                                        if (sys_stat(argv[Optind], &stbuf) == 0) {
                                                newer_than = stbuf.st_mtime;
                                                DEBUG(1,("Getting files newer than %s",
-                                                       asctime(localtime(&newer_than))));
+                                                       time_to_asc(&newer_than)));
                                                newOptind++;
                                                Optind++;
                                        } else {
index ba095aee84e6ddadaf191e3e1bc9a36e332ac296..5b21d195b76521d7f7f4b6d6ae2bc72fc46a2bc1 100644 (file)
@@ -445,7 +445,7 @@ static void display_finfo(file_info *finfo)
                         finfo->name,
                         attrib_string(finfo->mode),
                         (double)finfo->size,
-                        asctime(localtime(&t)));
+                        time_to_asc(&t));
                dir_total += finfo->size;
        }
 }
@@ -458,7 +458,7 @@ static void display_stat(char *name, struct stat *st)
 {
        time_t t = st->st_mtime;
        pstring time_str;
-       pstrcpy(time_str, asctime(localtime(&t)));
+       pstrcpy(time_str, time_to_asc(&t));
        time_str[strlen(time_str)-1] = 0;
        d_printf("> %-30s", name);
        d_printf("%10.10s %8.0f  %s\n", *mode_t_string(st->st_mode), (double)st->st_size, time_str);
@@ -2303,6 +2303,7 @@ static int cmd_stat(void)
        fstring mode_str;
        SMB_STRUCT_STAT sbuf;
        struct cli_state *targetcli;
+       struct tm *lt;
        pstring targetname;
  
        if (!SERVER_HAS_UNIX_CIFS(cli)) {
@@ -2357,15 +2358,30 @@ static int cmd_stat(void)
                (unsigned int)sbuf.st_uid, 
                (unsigned int)sbuf.st_gid);
 
-       strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_atime));
+       lt = localtime(&sbuf.st_atime);
+       if (lt) {
+               strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+       } else {
+               fstrcpy(mode_str, "unknown");
+       }
        d_printf("Access: %s\n", mode_str);
 
-       strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_mtime));
+       lt = localtime(&sbuf.st_mtime);
+       if (lt) {
+               strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+       } else {
+               fstrcpy(mode_str, "unknown");
+       }
        d_printf("Modify: %s\n", mode_str);
 
-       strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_ctime));
+       lt = localtime(&sbuf.st_ctime);
+       if (lt) {
+               strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+       } else {
+               fstrcpy(mode_str, "unknown");
+       }
        d_printf("Change: %s\n", mode_str);
-       
+
        return 0;
 }
 
@@ -2538,7 +2554,7 @@ static int cmd_newer(void)
        if (ok && (sys_stat(buf,&sbuf) == 0)) {
                newer_than = sbuf.st_mtime;
                DEBUG(1,("Getting files newer than %s",
-                        asctime(localtime(&newer_than))));
+                        time_to_asc(&newer_than)));
        } else {
                newer_than = 0;
        }
index 9ef3503d39f712ce187b22cdfd52a3e7fbf3111f..19b37af93868c8787d11fada46b750ef2f78996c 100644 (file)
@@ -95,49 +95,50 @@ Corrections by richard.kettlewell@kewill.com
 #define  YEAR    365*DAY
  time_t mktime(struct tm *t)
 {
-  struct tm       *u;
-  time_t  epoch = 0;
-  int n;
-  int             mon [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
-  y, m, i;
-
-  if(t->tm_year < 70)
-    return((time_t)-1);
-
-  n = t->tm_year + 1900 - 1;
-  epoch = (t->tm_year - 70) * YEAR + 
-    ((n / 4 - n / 100 + n / 400) - (1969 / 4 - 1969 / 100 + 1969 / 400)) * DAY;
-
-  y = t->tm_year + 1900;
-  m = 0;
-
-  for(i = 0; i < t->tm_mon; i++) {
-    epoch += mon [m] * DAY;
-    if(m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
-      epoch += DAY;
+       struct tm       *u;
+       time_t  epoch = 0;
+       int n;
+       int             mon [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+       y, m, i;
+
+       if(t->tm_year < 70) {
+               return((time_t)-1);
+       }
+
+       n = t->tm_year + 1900 - 1;
+       epoch = (t->tm_year - 70) * YEAR + ((n / 4 - n / 100 + n / 400) - (1969 / 4 - 1969 / 100 + 1969 / 400)) * DAY;
+
+       y = t->tm_year + 1900;
+       m = 0;
+
+       for(i = 0; i < t->tm_mon; i++) {
+               epoch += mon [m] * DAY;
+               if(m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
+                       epoch += DAY;
+               }
     
-    if(++m > 11) {
-      m = 0;
-      y++;
-    }
-  }
-
-  epoch += (t->tm_mday - 1) * DAY;
-  epoch += t->tm_hour * HOUR + t->tm_min * MINUTE + t->tm_sec;
+               if(++m > 11) {
+                       m = 0;
+                       y++;
+               }
+       }
+
+       epoch += (t->tm_mday - 1) * DAY;
+       epoch += t->tm_hour * HOUR + t->tm_min * MINUTE + t->tm_sec;
   
-  if((u = localtime(&epoch)) != NULL) {
-    t->tm_sec = u->tm_sec;
-    t->tm_min = u->tm_min;
-    t->tm_hour = u->tm_hour;
-    t->tm_mday = u->tm_mday;
-    t->tm_mon = u->tm_mon;
-    t->tm_year = u->tm_year;
-    t->tm_wday = u->tm_wday;
-    t->tm_yday = u->tm_yday;
-    t->tm_isdst = u->tm_isdst;
-  }
-
-  return(epoch);
+       if((u = localtime(&epoch)) != NULL) {
+               t->tm_sec = u->tm_sec;
+               t->tm_min = u->tm_min;
+               t->tm_hour = u->tm_hour;
+               t->tm_mday = u->tm_mday;
+               t->tm_mon = u->tm_mon;
+               t->tm_year = u->tm_year;
+               t->tm_wday = u->tm_wday;
+               t->tm_yday = u->tm_yday;
+               t->tm_isdst = u->tm_isdst;
+       }
+
+       return(epoch);
 }
 #endif /* !HAVE_MKTIME */
 
@@ -147,15 +148,15 @@ Corrections by richard.kettlewell@kewill.com
 /* Rename a file. (from libiberty in GNU binutils)  */
  int rename(const char *zfrom, const char *zto)
 {
-  if (link (zfrom, zto) < 0)
-    {
-      if (errno != EEXIST)
-       return -1;
-      if (unlink (zto) < 0
-         || link (zfrom, zto) < 0)
-       return -1;
-    }
-  return unlink (zfrom);
+       if (link (zfrom, zto) < 0) {
+               if (errno != EEXIST) {
+                       return -1;
+               }
+               if (unlink (zto) < 0 || link (zfrom, zto) < 0) {
+                       return -1;
+               }
+       }
+       return unlink (zfrom);
 }
 #endif /* HAVE_RENAME */
 
index f8a1538910c49c5baf80da748264b1cd1b7936c6..9a539d415e880414c2991b86234d2facc61c77ff 100644 (file)
@@ -615,16 +615,19 @@ char *http_timestring(time_t t)
        static fstring buf;
        struct tm *tm = localtime(&t);
 
-       if (!tm)
+       if (!tm) {
                slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t);
-       else
+       } else {
 #ifndef HAVE_STRFTIME
-               fstrcpy(buf, asctime(tm));
-       if(buf[strlen(buf)-1] == '\n')
+               const char *asct = asctime(tm);
+               fstrcpy(buf, asct ? asct : "unknown");
+       }
+       if(buf[strlen(buf)-1] == '\n') {
                buf[strlen(buf)-1] = 0;
 #else /* !HAVE_STRFTIME */
                strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
 #endif /* !HAVE_STRFTIME */
+       }
        return buf;
 }
 
@@ -672,13 +675,15 @@ char *timestring(BOOL hires)
                }
 #else
                if (hires) {
+                       const char *asct = asctime(tm);
                        slprintf(TimeBuf, 
                                 sizeof(TimeBuf)-1, 
                                 "%s.%06ld", 
-                                asctime(tm)
+                                asct ? asct : "unknown"
                                 (long)tp.tv_usec);
                } else {
-                       fstrcpy(TimeBuf, asctime(tm));
+                       const char *asct = asctime(tm);
+                       fstrcpy(TimeBuf, asct ? asct : "unknown");
                }
 #endif
        }
@@ -1050,3 +1055,24 @@ struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs)
        return ret;
 }
 #endif
+
+/****************************************************************************
+ Utility function that always returns a const string even if localtime
+ and asctime fail.
+****************************************************************************/
+
+const char *time_to_asc(const time_t *t)
+{
+       const char *asct;
+       struct tm *lt = localtime(t);
+
+       if (!lt) {
+               return "unknown time";
+       }
+
+       asct = asctime(lt);
+       if (!asct) {
+               return "unknown time";
+       }
+       return asct;
+}
index 60023a7ed5e994b8939ce260097f883104858876..fb32ce1aad1b66318d246be6cdcd2b8d8de211d1 100644 (file)
@@ -564,15 +564,31 @@ void dump_name_record( struct name_record *namerec, XFILE *fp)
        x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
 
        if(namerec->data.death_time != PERMANENT_TTL) {
+               const char *asct;
                tm = localtime(&namerec->data.death_time);
-               x_fprintf(fp, "death_time = %s\t", asctime(tm));
+               if (!tm) {
+                       return;
+               }
+               asct = asctime(tm);
+               if (!asct) {
+                       return;
+               }
+               x_fprintf(fp, "death_time = %s\t", asct);
        } else {
                x_fprintf(fp, "death_time = PERMANENT\t");
        }
 
        if(namerec->data.refresh_time != PERMANENT_TTL) {
+               const char *asct;
                tm = localtime(&namerec->data.refresh_time);
-               x_fprintf(fp, "refresh_time = %s\n", asctime(tm));
+               if (!tm) {
+                       return;
+               }
+               asct = asctime(tm);
+               if (!asct) {
+                       return;
+               }
+               x_fprintf(fp, "refresh_time = %s\n", asct);
        } else {
                x_fprintf(fp, "refresh_time = PERMANENT\n");
        }
index 198d90f35a15ee9d5d6e4eddba762780ff9f4033..29d5c41de821952a747e4593412f6a7ab281ab3d 100644 (file)
@@ -2222,7 +2222,13 @@ void wins_write_name_record(struct name_record *namerec, XFILE *fp)
                char *ts, *nl;
 
                tm = localtime(&namerec->data.death_time);
+               if (!tm) {
+                       return;
+               }
                ts = asctime(tm);
+               if (!ts) {
+                       return;
+               }
                nl = strrchr( ts, '\n' );
                if( NULL != nl ) {
                        *nl = '\0';
index 7e81b5187c9cef1579a24c8e848db7f3cf944ebd..324d0fa90dc9ee298ef5fc513874c0aaa6d0d181 100644 (file)
@@ -25,50 +25,62 @@ static const char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
 
 
 /*******************************************************************
-process time fields
+ Process time fields
 ********************************************************************/
+
 static time_t EntryTime(fstring tok[], int ptr, int count, int minimum)
 {
-  time_t jobtime,jobtime1;
-
-  jobtime = time(NULL);                /* default case: take current time */
-  if (count >= minimum) {
-    struct tm *t;
-    int i, day, hour, min, sec;
-    char   *c;
-
-    for (i=0; i<13; i++) if (!strncmp(tok[ptr], Months[i],3)) break; /* Find month */
-    if (i<12) {
-      t = localtime(&jobtime);
-      day = atoi(tok[ptr+1]);
-      c=(char *)(tok[ptr+2]);
-      *(c+2)=0;
-      hour = atoi(c);
-      *(c+5)=0;
-      min = atoi(c+3);
-      if(*(c+6) != 0)sec = atoi(c+6);
-      else  sec=0;
-
-      if ((t->tm_mon < i)||
-         ((t->tm_mon == i)&&
-          ((t->tm_mday < day)||
-           ((t->tm_mday == day)&&
-            (t->tm_hour*60+t->tm_min < hour*60+min)))))
-       t->tm_year--;           /* last year's print job */
-
-      t->tm_mon = i;
-      t->tm_mday = day;
-      t->tm_hour = hour;
-      t->tm_min = min;
-      t->tm_sec = sec;
-      jobtime1 = mktime(t);
-      if (jobtime1 != (time_t)-1)
-       jobtime = jobtime1;
-    }
-  }
-  return jobtime;
-}
+       time_t jobtime,jobtime1;
+
+       jobtime = time(NULL);           /* default case: take current time */
+       if (count >= minimum) {
+               struct tm *t;
+               int i, day, hour, min, sec;
+               char   *c;
+
+               for (i=0; i<13; i++) {
+                       if (!strncmp(tok[ptr], Months[i],3)) {
+                               break; /* Find month */
+                       }
+               }
 
+               if (i<12) {
+                       t = localtime(&jobtime);
+                       if (!t) {
+                               return (time_t)-1;
+                       }
+                       day = atoi(tok[ptr+1]);
+                       c=(char *)(tok[ptr+2]);
+                       *(c+2)=0;
+                       hour = atoi(c);
+                       *(c+5)=0;
+                       min = atoi(c+3);
+                       if(*(c+6) != 0) {
+                               sec = atoi(c+6);
+                       } else {
+                               sec=0;
+                       }
+
+                       if ((t->tm_mon < i)|| ((t->tm_mon == i)&&
+                                       ((t->tm_mday < day)||
+                                       ((t->tm_mday == day)&&
+                                       (t->tm_hour*60+t->tm_min < hour*60+min))))) {
+                               t->tm_year--;           /* last year's print job */
+                       }
+
+                       t->tm_mon = i;
+                       t->tm_mday = day;
+                       t->tm_hour = hour;
+                       t->tm_min = min;
+                       t->tm_sec = sec;
+                       jobtime1 = mktime(t);
+                       if (jobtime1 != (time_t)-1) {
+                               jobtime = jobtime1;
+                       }
+               }
+       }
+       return jobtime;
+}
 
 /****************************************************************************
 parse a lpq line
@@ -190,24 +202,27 @@ With lprng 3.16 The lpq time looks like
 static time_t LPRng_time(char *time_string)
 {
        time_t jobtime;
-       struct tm t;
+       struct tm *t;
 
        jobtime = time(NULL);         /* default case: take current time */
-       t = *localtime(&jobtime);
+       t = localtime(&jobtime);
+       if (!t) {
+               return (time_t)-1;
+       }
 
        if ( atoi(time_string) < 24 ){
-               t.tm_hour = atoi(time_string);
-               t.tm_min = atoi(time_string+3);
-               t.tm_sec = atoi(time_string+6);
+               t->tm_hour = atoi(time_string);
+               t->tm_min = atoi(time_string+3);
+               t->tm_sec = atoi(time_string+6);
        } else {
-               t.tm_year = atoi(time_string)-1900;
-               t.tm_mon = atoi(time_string+5)-1;
-               t.tm_mday = atoi(time_string+8);
-               t.tm_hour = atoi(time_string+11);
-               t.tm_min = atoi(time_string+14);
-               t.tm_sec = atoi(time_string+17);
+               t->tm_year = atoi(time_string)-1900;
+               t->tm_mon = atoi(time_string+5)-1;
+               t->tm_mday = atoi(time_string+8);
+               t->tm_hour = atoi(time_string+11);
+               t->tm_min = atoi(time_string+14);
+               t->tm_sec = atoi(time_string+17);
        }    
-       jobtime = mktime(&t);
+       jobtime = mktime(t);
 
        return jobtime;
 }
index 4d4d9d225917b295396146872764a30aeae59633..7d1a2ade5441c3812a694a00dd74bf5c2f4dd069 100644 (file)
@@ -2212,6 +2212,9 @@ static BOOL api_NetRemoteTOD(connection_struct *conn,uint16 vuid, char *param,ch
        /* the client expects to get localtime, not GMT, in this bit 
                (I think, this needs testing) */
        t = localtime(&unixdate);
+       if (!t) {
+               return False;
+       }
 
        SIVAL(p,4,0);           /* msecs ? */
        SCVAL(p,8,t->tm_hour);
index 0c107a5f01d0a53697fdfa816eda99643cb4bb90..69b3327f7a97be6fe623df8c73cc8fdda7c42570 100644 (file)
 static void print_cache_entry(const char* keystr, const char* datastr,
                               const time_t timeout, void* dptr)
 {
-       chartimeout_str;
+       char *timeout_str;
        time_t now_t = time(NULL);
        struct tm timeout_tm, *now_tm;
        /* localtime returns statically allocated pointer, so timeout_tm
           has to be copied somewhere else */
-       memcpy(&timeout_tm, localtime(&timeout), sizeof(struct tm));
+
+       now_tm = localtime(&timeout);
+       if (!now_tm) {
+               return;
+       }
+       memcpy(&timeout_tm, now_tm, sizeof(struct tm));
        now_tm = localtime(&now_t);
+       if (!now_tm) {
+               return;
+       }
 
        /* form up timeout string depending whether it's today's date or not */
        if (timeout_tm.tm_year != now_tm->tm_year ||
-           timeout_tm.tm_mon != now_tm->tm_mon ||
-           timeout_tm.tm_mday != now_tm->tm_mday) {
+                       timeout_tm.tm_mon != now_tm->tm_mon ||
+                       timeout_tm.tm_mday != now_tm->tm_mday) {
            
-           timeout_str = asctime(&timeout_tm);
-           timeout_str[strlen(timeout_str) - 1] = '\0';        /* remove tailing CR */
-       } else
+               timeout_str = asctime(&timeout_tm);
+               if (!timeout_str) {
+                       return;
+               }       
+               timeout_str[strlen(timeout_str) - 1] = '\0';    /* remove tailing CR */
+       } else {
                asprintf(&timeout_str, "%.2d:%.2d:%.2d", timeout_tm.tm_hour,
                         timeout_tm.tm_min, timeout_tm.tm_sec);
+       }
        
        d_printf("Key: %s\t Timeout: %s\t Value: %s  %s\n", keystr,
                 timeout_str, datastr, timeout > now_t ? "": "(expired)");
index d85bd27b16d82bb148e89be5becfc7721f6b04a8..c68c9f6e2fb365a0790b779c929d69ec2b2ae573 100644 (file)
@@ -104,7 +104,7 @@ static int show_share(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
        d_printf("%-10.10s   %s   %-12s  %s",
               crec.name,procid_str_static(&crec.pid),
               crec.machine,
-              asctime(localtime(&crec.start)));
+              time_to_asc(&crec.start));
 
        return 0;
 }
@@ -173,7 +173,7 @@ static int show_share_parseable(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
                 guest ? "" : gidtoname(ids->entries[i].gid),
                 crec.machine, 
                 guest ? "" : ids->entries[i].hostname,
-                asctime(localtime(&crec.start)));
+                time_to_asc(&crec.start));
 
        return 0;
 }
index 1a7116d447d992e3c49318c59a3e6e3bd5a78012..f6486286a65f466b885fb6e1d96063253adcee9f 100644 (file)
@@ -69,12 +69,15 @@ static time_t nettime(int *zone)
 }
 
 /* return a time as a string ready to be passed to /bin/date */
-static char *systime(time_t t)
+static const char *systime(time_t t)
 {
        static fstring s;
        struct tm *tm;
 
        tm = localtime(&t);
+       if (!tm) {
+               return "unknown";
+       }
        
        fstr_sprintf(s, "%02d%02d%02d%02d%04d.%02d", 
                 tm->tm_mon+1, tm->tm_mday, tm->tm_hour, 
index 05075da444fbb9fd76d26ad4cb1df65fc3ff8dfc..2566c8a50def54fbfab74844144ca8bf55a20b83 100644 (file)
@@ -155,7 +155,7 @@ static void print_share_mode(const struct share_mode_entry *e, const char *share
                        d_printf("NONE            ");
                }
 
-               d_printf(" %s   %s   %s",sharepath, fname, asctime(localtime((time_t *)&e->time.tv_sec)));
+               d_printf(" %s   %s   %s",sharepath, fname, time_to_asc((time_t *)&e->time.tv_sec));
        }
 }
 
@@ -562,7 +562,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st
        d_printf("%-10s   %s   %-12s  %s",
               crec.name,procid_str_static(&crec.pid),
               crec.machine,
-              asctime(localtime(&crec.start)));
+              time_to_asc(&crec.start));
 
        return 0;
 }
index 7430f4ebf59977360506b130f0c3feb71068c0e6..769ab217b3edb3d6746dc6214184fc3efbd4ef1d 100644 (file)
@@ -101,7 +101,7 @@ static char *mapPid2Machine (struct process_id pid)
 static char *tstring(time_t t)
 {
        static pstring buf;
-       pstrcpy(buf, asctime(localtime(&t)));
+       pstrcpy(buf, time_to_asc(&t));
        all_string_sub(buf," ","&nbsp;",sizeof(buf));
        return buf;
 }