Welcome, Guest. Please login or register.

Author Topic: Amiga UNIX Y2K problem...no problem?  (Read 2252 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Amiga UNIX Y2K problem...no problem?
« on: February 11, 2006, 08:47:38 AM »
The bug was in sscanf() using %02d for the year. The year is 3 digits with years 2000++ so only first two first digits were parsed (year ended up 10 instead of 106). Also various buffers had to be extended to accommodate the extra char so no buffer overflow will occur.

Now assuming /usr/bin/date can handle 3 digit date (for example: 02111032106 that is: feb 11th 10:32 1900+106 = 2006), here is a fix:

Code: [Select]

--- setclk.c-orig Sat Feb 11 02:48:57 2006
+++ setclk.c Sat Feb 11 10:41:14 2006
@@ -51,7 +51,7 @@
 
     if (!strcmp(*argv, "getclk"))
     {
- char buffer[11];
+ char buffer[12];
 
  retval = read_clock(buffer);
 
@@ -80,7 +80,7 @@
     if (argc == 1)
     {
  time_t thetime = read_from_clock_device();
- char buffer[BUFSIZ*2], tmpbuf[sizeof("MMDDhhmmYY")];
+ char buffer[BUFSIZ*2], tmpbuf[sizeof("MMDDhhmmYYY")];
 
  /*
  ** Set the system time to what the hardware thinks is correct.
@@ -138,7 +138,7 @@
 
     if (set_clock)
     {
- char buffer[11];
+ char buffer[12];
  struct tm *tm;
  time_t thetime;
 
@@ -175,7 +175,7 @@
 
     if (display_clock)
     {
- char buffer[11];
+ char buffer[12];
 
  retval = read_clock(buffer);
 
@@ -299,7 +299,7 @@
  return FALSE;
     }
 
-    if (sscanf(buffer, "%02d%02d%02d%02d%02d", &month, &days, &hours, &mins,
+    if (sscanf(buffer, "%02d%02d%02d%02d%03d", &month, &days, &hours, &mins,
         &year) != 5)
     {
  (void) fprintf(stderr, "%s: Bad date format \"%s\"\n", progname,


However, if date can't grock it (which might well be the case), /usr/bin/date itself has to be fixed aswell (or if it handles < 70 year by adding 100, the parsed date has to be adjusted with 'if (year > 99) year -= 100;').

If you find the patch above useful please feel free to use it as you wish. I hereby place it in public domain.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Amiga UNIX Y2K problem...no problem?
« Reply #1 on: September 27, 2007, 10:47:38 PM »
Cool :-)