[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bash time_t porting problems (including Y2038 and Y6053 bugs)
From: |
Paul Eggert |
Subject: |
bash time_t porting problems (including Y2038 and Y6053 bugs) |
Date: |
Thu, 12 Apr 2001 20:40:22 -0700 (PDT) |
Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc'
-DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8'
-DCONF_VENDOR='sun' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib
-I/opt/reb/include -g -O2 -Wall
uname output: SunOS shade.twinsun.com 5.8 Generic_108528-06 sun4u sparc
SUNW,Ultra-1
Machine Type: sparc-sun-solaris2.8
Bash Version: 2.05
Patch Level: 0
Release Status: release
Description:
In several places, 'bash' uses 'long' where it should use time_t;
this can make a difference on hosts where time_t is unsigned long.
In one place, 'bash' uses 'int' where it should use time_t; this
makes a difference on hosts where 'int' is 32 bits but time_t is
64 bits.
These two bugs manifest themselves for time stamps after 2038.
In couple of other places, 'bash' uses 'int' to store the number
of minutes since the epoch; on hosts with 32-bit int and 64-bit
time_t, this will fail for time stamps after the year 6053.
Repeat-By:
Set the clock to a value past the year 6053 on 64-bit Solaris 8.
Fix:
2001-04-12 Paul Eggert <eggert@twinsun.com>
* mailcheck.c (last_time_mail_checked): Use time_t, not 'int',
since this records a time stamp value.
(time_to_check_mail): Do not assume that MAILCHECK interval fits into
'int'. Check more carefully for invalid integers.
* execute_cmd.c (mkfmt, print_formatted_time, time_command):
Use time_t, not 'long', to record time stamps.
* lib/sh/timeval.c (timeval_to_secs, print_timeval): Likewise.
Do not assumes that 'minutes' fits into int.
* lib/sh/clock.c (clock_t_to_secs, print_clock_t): Likewise.
===================================================================
RCS file: execute_cmd.c,v
retrieving revision 2.5.0.1
retrieving revision 2.5.0.2
diff -pu -r2.5.0.1 -r2.5.0.2
--- execute_cmd.c 2001/04/13 00:32:06 2.5.0.1
+++ execute_cmd.c 2001/04/13 00:46:05 2.5.0.2
@@ -808,10 +808,10 @@ static int
mkfmt (buf, prec, lng, sec, sec_fraction)
char *buf;
int prec, lng;
- long sec;
+ time_t sec;
int sec_fraction;
{
- long min;
+ time_t min;
char abuf[16];
int ind, aind;
@@ -883,12 +883,12 @@ static void
print_formatted_time (fp, format, rs, rsf, us, usf, ss, ssf, cpu)
FILE *fp;
char *format;
- long rs, us, ss;
+ time_t rs, us, ss;
int rsf, usf, ssf, cpu;
{
int prec, lng, len;
char *str, *s, ts[32];
- long sum;
+ time_t sum;
int sum_frac;
int sindex, ssize;
@@ -969,7 +969,7 @@ time_command (command, asynchronous, pip
struct fd_bitmap *fds_to_close;
{
int rv, posix_time, old_flags;
- long rs, us, ss;
+ time_t rs, us, ss;
int rsf, usf, ssf;
int cpu;
char *time_format;
@@ -1003,7 +1003,7 @@ time_command (command, asynchronous, pip
rv = execute_command_internal (command, asynchronous, pipe_in, pipe_out,
fds_to_close);
command->flags = old_flags;
- rs = us = ss = 0L;
+ rs = us = ss = 0;
rsf = usf = ssf = cpu = 0;
#if defined (HAVE_GETRUSAGE) && defined (HAVE_GETTIMEOFDAY)
@@ -1039,7 +1039,7 @@ time_command (command, asynchronous, pip
cpu = (real == 0) ? 0 : ((user + sys) * 10000) / real;
# else
- rs = us = ss = 0L;
+ rs = us = ss = 0;
rsf = usf = ssf = cpu = 0;
# endif
#endif
===================================================================
RCS file: mailcheck.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- mailcheck.c 2001/02/14 21:59:15 2.5
+++ mailcheck.c 2001/04/13 00:46:05 2.5.0.1
@@ -56,7 +56,7 @@ static FILEINFO **mailfiles = (FILEINFO
static int mailfiles_count;
/* The last known time that mail was checked. */
-static int last_time_mail_checked;
+static time_t last_time_mail_checked;
/* Non-zero means warn if a mail file has been read since last checked. */
int mail_warning;
@@ -70,20 +70,10 @@ time_to_check_mail ()
long seconds;
temp = get_string_value ("MAILCHECK");
- seconds = -1L;
-
- /* Skip leading whitespace in MAILCHECK. */
- if (temp)
- {
- while (whitespace (*temp))
- temp++;
-
- seconds = atoi (temp);
- }
/* Negative number, or non-numbers (such as empty string) cause no
checking to take place. */
- if (seconds < 0)
+ if (!temp || !legal_number (temp, &seconds) || seconds < 0)
return (0);
now = NOW;
===================================================================
RCS file: lib/sh/clock.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- lib/sh/clock.c 1999/08/16 16:20:39 2.5
+++ lib/sh/clock.c 2001/04/13 00:46:05 2.5.0.1
@@ -34,7 +34,7 @@
void
clock_t_to_secs (t, sp, sfp)
clock_t t;
- long *sp;
+ time_t *sp;
int *sfp;
{
static long clk_tck = -1;
@@ -64,15 +64,16 @@ print_clock_t (fp, t)
FILE *fp;
clock_t t;
{
- int minutes, seconds_fraction;
- long seconds;
+ time_t timestamp;
+ long minutes;
+ int seconds, seconds_fraction;
- clock_t_to_secs (t, &seconds, &seconds_fraction);
+ clock_t_to_secs (t, ×tamp, &seconds_fraction);
- minutes = seconds / 60;
- seconds %= 60;
+ minutes = timestamp / 60;
+ seconds = timestamp % 60;
- fprintf (fp, "%0dm%0ld.%03ds", minutes, seconds, seconds_fraction);
+ fprintf (fp, "%ldm%d.%03ds", minutes, seconds, seconds_fraction);
}
#endif /* HAVE_TIMES */
===================================================================
RCS file: lib/sh/timeval.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- lib/sh/timeval.c 1999/08/16 16:01:47 2.5
+++ lib/sh/timeval.c 2001/04/13 00:46:05 2.5.0.1
@@ -103,7 +103,7 @@ timeval_to_cpu (rt, ut, st)
void
timeval_to_secs (tvp, sp, sfp)
struct timeval *tvp;
- long *sp;
+ time_t *sp;
int *sfp;
{
int rest;
@@ -131,14 +131,15 @@ print_timeval (fp, tvp)
FILE *fp;
struct timeval *tvp;
{
- int minutes, seconds_fraction;
- long seconds;
+ time_t timestamp;
+ long minutes;
+ int seconds, seconds_fraction;
- timeval_to_secs (tvp, &seconds, &seconds_fraction);
+ timeval_to_secs (tvp, ×tamp, &seconds_fraction);
- minutes = seconds / 60;
- seconds %= 60;
+ minutes = timestamp / 60;
+ seconds = timestamp % 60;
- fprintf (fp, "%0dm%0ld.%03ds", minutes, seconds, seconds_fraction);
+ fprintf (fp, "%ldm%d.%03ds", minutes, seconds, seconds_fraction);
}
#endif /* HAVE_TIMEVAL */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bash time_t porting problems (including Y2038 and Y6053 bugs),
Paul Eggert <=