asctime/ctime: Check for too low input time, fixes one msvcrt time winetest
authorGregor Schneider <grschneider@gmail.com>
Wed, 5 Aug 2009 02:06:25 +0000 (02:06 +0000)
committerGregor Schneider <grschneider@gmail.com>
Wed, 5 Aug 2009 02:06:25 +0000 (02:06 +0000)
svn path=/trunk/; revision=42402

reactos/lib/sdk/crt/time/ctime.c

index fd7eda2..49b89a5 100644 (file)
@@ -1200,14 +1200,23 @@ asctime(const struct tm *timeptr)
     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
   };
   static char result[26];
+  char* res = result;
 
-  (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
-         wday_name[timeptr->tm_wday],
-         mon_name[timeptr->tm_mon],
-         timeptr->tm_mday, timeptr->tm_hour,
-         timeptr->tm_min, timeptr->tm_sec,
-         TM_YEAR_BASE + timeptr->tm_year);
-  return result;
+  /* Check for invalid input time */
+  if (timeptr->tm_year <= 69)
+  {
+    res = NULL;
+  }
+  else
+  {
+    sprintf(res, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
+            wday_name[timeptr->tm_wday],
+            mon_name[timeptr->tm_mon],
+            timeptr->tm_mday, timeptr->tm_hour,
+            timeptr->tm_min, timeptr->tm_sec,
+            TM_YEAR_BASE + timeptr->tm_year);
+  }
+  return res;
 }
 
 /*