aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2006-03-27 20:40:05 +0000
committerPaul Eggert2006-03-27 20:40:05 +0000
commitf55658040dbc67b3acf345d82d017e47389b0727 (patch)
tree0add62d9c9ae6aa128f300e2ccb548d0869f36a8 /lib-src
parentab5523ffae1f91e6edcb3bf57e1628bda098b655 (diff)
downloademacs-f55658040dbc67b3acf345d82d017e47389b0727.tar.gz
emacs-f55658040dbc67b3acf345d82d017e47389b0727.zip
* b2m.c: Include <limits.h>.
(TM_YEAR_IN_ASCTIME_RANGE): New macro. (main): Check for out-of-range time stamps. * fakemail.c: Likewise.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog7
-rw-r--r--lib-src/b2m.c21
-rw-r--r--lib-src/fakemail.c21
3 files changed, 47 insertions, 2 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index f59f7296359..72ff56c2dfd 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,10 @@
12006-03-27 Paul Eggert <eggert@cs.ucla.edu>
2
3 * b2m.c: Include <limits.h>.
4 (TM_YEAR_IN_ASCTIME_RANGE): New macro.
5 (main): Check for out-of-range time stamps.
6 * fakemail.c: Likewise.
7
12006-03-18 Andre Spiegel <spiegel@gnu.org> 82006-03-18 Andre Spiegel <spiegel@gnu.org>
2 9
3 * vcdiff: Use "echo" as a default for $echo, otherwise we'll 10 * vcdiff: Use "echo" as a default for $echo, otherwise we'll
diff --git a/lib-src/b2m.c b/lib-src/b2m.c
index 5bebe560e2a..adaa736bcd9 100644
--- a/lib-src/b2m.c
+++ b/lib-src/b2m.c
@@ -26,6 +26,7 @@
26#undef static 26#undef static
27#endif 27#endif
28 28
29#include <limits.h>
29#include <stdio.h> 30#include <stdio.h>
30#include <time.h> 31#include <time.h>
31#include <sys/types.h> 32#include <sys/types.h>
@@ -44,6 +45,17 @@
44 45
45typedef int logical; 46typedef int logical;
46 47
48/* True if TM_YEAR is a struct tm's tm_year value that is acceptable
49 to asctime. Glibc asctime returns a useful string unless TM_YEAR
50 is nearly INT_MAX, but the C Standard lets C libraries overrun a
51 buffer if TM_YEAR needs more than 4 bytes. */
52#ifdef __GLIBC__
53# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) ((tm_year) <= INT_MAX - 1900)
54#else
55# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \
56 (-999 - 1900 <= (tm_year) && (tm_year) <= 9999 - 1900)
57#endif
58
47/* 59/*
48 * A `struct linebuffer' is a structure which holds a line of text. 60 * A `struct linebuffer' is a structure which holds a line of text.
49 * `readline' reads a line from a stream into a linebuffer and works 61 * `readline' reads a line from a stream into a linebuffer and works
@@ -87,6 +99,7 @@ main (argc, argv)
87{ 99{
88 logical labels_saved, printing, header; 100 logical labels_saved, printing, header;
89 time_t ltoday; 101 time_t ltoday;
102 struct tm *tm;
90 char *labels, *p, *today; 103 char *labels, *p, *today;
91 struct linebuffer data; 104 struct linebuffer data;
92 105
@@ -131,7 +144,13 @@ main (argc, argv)
131 144
132 labels_saved = printing = header = FALSE; 145 labels_saved = printing = header = FALSE;
133 ltoday = time (0); 146 ltoday = time (0);
134 today = ctime (&ltoday); 147 /* Convert to a string, checking for out-of-range time stamps.
148 Don't use 'ctime', as that might dump core if the hardware clock
149 is set to a bizarre value. */
150 tm = localtime (&ltoday);
151 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year)))
152 fatal ("current time is out of range");
153 today = asctime (tm);
135 data.size = 200; 154 data.size = 200;
136 data.buffer = xnew (200, char); 155 data.buffer = xnew (200, char);
137 156
diff --git a/lib-src/fakemail.c b/lib-src/fakemail.c
index c8bfcfc0931..2c2b462e366 100644
--- a/lib-src/fakemail.c
+++ b/lib-src/fakemail.c
@@ -53,6 +53,7 @@ main ()
53#include "ntlib.h" 53#include "ntlib.h"
54#endif 54#endif
55 55
56#include <limits.h>
56#include <stdio.h> 57#include <stdio.h>
57#include <string.h> 58#include <string.h>
58#include <ctype.h> 59#include <ctype.h>
@@ -70,6 +71,17 @@ main ()
70#define true 1 71#define true 1
71#define false 0 72#define false 0
72 73
74/* True if TM_YEAR is a struct tm's tm_year value that is acceptable
75 to asctime. Glibc asctime returns a useful string unless TM_YEAR
76 is nearly INT_MAX, but the C Standard lets C libraries overrun a
77 buffer if TM_YEAR needs more than 4 bytes. */
78#ifdef __GLIBC__
79# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) ((tm_year) <= INT_MAX - 1900)
80#else
81# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \
82 (-999 - 1900 <= (tm_year) && (tm_year) <= 9999 - 1900)
83#endif
84
73/* Various lists */ 85/* Various lists */
74 86
75struct line_record 87struct line_record
@@ -354,6 +366,7 @@ make_file_preface ()
354{ 366{
355 char *the_string, *temp; 367 char *the_string, *temp;
356 long idiotic_interface; 368 long idiotic_interface;
369 struct tm *tm;
357 long prefix_length; 370 long prefix_length;
358 long user_length; 371 long user_length;
359 long date_length; 372 long date_length;
@@ -361,7 +374,13 @@ make_file_preface ()
361 374
362 prefix_length = strlen (FROM_PREFIX); 375 prefix_length = strlen (FROM_PREFIX);
363 time (&idiotic_interface); 376 time (&idiotic_interface);
364 the_date = ctime (&idiotic_interface); 377 /* Convert to a string, checking for out-of-range time stamps.
378 Don't use 'ctime', as that might dump core if the hardware clock
379 is set to a bizarre value. */
380 tm = localtime (&idiotic_interface);
381 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year)))
382 fatal ("current time is out of range", 0);
383 the_date = asctime (tm);
365 /* the_date has an unwanted newline at the end */ 384 /* the_date has an unwanted newline at the end */
366 date_length = strlen (the_date) - 1; 385 date_length = strlen (the_date) - 1;
367 the_date[date_length] = '\0'; 386 the_date[date_length] = '\0';