diff mbox

[1/4] dmi: fix date handling in dmi_get_year()

Message ID 4A87F512.3080802@kernel.org
State Not Applicable
Delegated to: David Miller
Headers show

Commit Message

Tejun Heo Aug. 16, 2009, 12:01 p.m. UTC
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: Tejun Heo <tj@kernel.org>
---
While trying to implement dmi_get_date(), spotted two bugs in the
current dmi_get_year().  Tricky date strings.  ;-P

I think it would be safer to postpone this and the next patch for the
next merge window.  There's no reported case of these bugs causing
problems yet, so no reason to risk behavior change at this stage.  If
nobody objects, it would be easiest to push this through
libata-dev#upstream.

Thanks.

 drivers/firmware/dmi_scan.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Jeff Garzik Aug. 16, 2009, 12:11 p.m. UTC | #1
Tejun Heo wrote:
> 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: Tejun Heo <tj@kernel.org>
> ---
> While trying to implement dmi_get_date(), spotted two bugs in the
> current dmi_get_year().  Tricky date strings.  ;-P
> 
> I think it would be safer to postpone this and the next patch for the
> next merge window.  There's no reported case of these bugs causing
> problems yet, so no reason to risk behavior change at this stage.  If
> nobody objects, it would be easiest to push this through
> libata-dev#upstream.
> 
> Thanks.
> 
>  drivers/firmware/dmi_scan.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Patchset looks good to me...   To make life easy, I would prefer to 
carry patches 1-2 in libata-dev#upstream, as well as patches 3-4.  If 
there are objections to that plan from anyone, speak now...  :)


	Jeff




--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jeff Garzik Sept. 9, 2009, 1:19 a.m. UTC | #2
On 08/16/2009 08:01 AM, Tejun Heo wrote:
> 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: Tejun Heo<tj@kernel.org>
> ---
> While trying to implement dmi_get_date(), spotted two bugs in the
> current dmi_get_year().  Tricky date strings.  ;-P
>
> I think it would be safer to postpone this and the next patch for the
> next merge window.  There's no reported case of these bugs causing
> problems yet, so no reason to risk behavior change at this stage.  If
> nobody objects, it would be easiest to push this through
> libata-dev#upstream.
>
> Thanks.
>
>   drivers/firmware/dmi_scan.c |    5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)

applied 1-4


--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

Index: ata/drivers/firmware/dmi_scan.c
===================================================================
--- ata.orig/drivers/firmware/dmi_scan.c
+++ ata/drivers/firmware/dmi_scan.c
@@ -577,6 +577,7 @@  int dmi_get_year(int field)
 {
 	int year;
 	const char *s = dmi_get_system_info(field);
+	char *e;
 
 	if (!s)
 		return -1;
@@ -587,8 +588,8 @@  int dmi_get_year(int field)
 		return 0;
 
 	s += 1;
-	year = simple_strtoul(s, NULL, 0);
-	if (year && year < 100) {	/* 2-digit year */
+	year = simple_strtoul(s, &e, 10);
+	if (s != e && year < 100) {	/* 2-digit year */
 		year += 1900;
 		if (year < 1996)	/* no dates < spec 1.0 */
 			year += 100;