Commit 02c24fa8 authored by Tejun Heo's avatar Tejun Heo Committed by Jeff Garzik

dmi: fix date handling in dmi_get_year()

Year parsing in dmi_get_year() had the following two bugs.

* "00" is treated as invalid instead of 2000 because zero return from
  simple_strtoul() is treated as error.

* "0N" where N >= 8 is treated as invalid of 200N because the leading
  0 is considered to specify octal.

Fix the above two bugs by using endptr to detect invalid number and
forcing decimal.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarJeff Garzik <jgarzik@redhat.com>
parent bd30add8
...@@ -577,6 +577,7 @@ int dmi_get_year(int field) ...@@ -577,6 +577,7 @@ int dmi_get_year(int field)
{ {
int year; int year;
const char *s = dmi_get_system_info(field); const char *s = dmi_get_system_info(field);
char *e;
if (!s) if (!s)
return -1; return -1;
...@@ -587,8 +588,8 @@ int dmi_get_year(int field) ...@@ -587,8 +588,8 @@ int dmi_get_year(int field)
return 0; return 0;
s += 1; s += 1;
year = simple_strtoul(s, NULL, 0); year = simple_strtoul(s, &e, 10);
if (year && year < 100) { /* 2-digit year */ if (s != e && year < 100) { /* 2-digit year */
year += 1900; year += 1900;
if (year < 1996) /* no dates < spec 1.0 */ if (year < 1996) /* no dates < spec 1.0 */
year += 100; year += 100;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment