All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cifs: small underflow in cnvrtDosUnixTm()
@ 2017-04-10 13:49 ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-04-10 13:49 UTC (permalink / raw)
  To: Steve French
  Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

January is month 1.  There is no zero-th month.  We don't care very much
if the days are invalid but for months, we use it to read from an array
so this bug means we read one space before the start of the
total_days_of_prev_months[] array.

Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
Signed-off-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>

diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index abae6dd2c6b9..f1f64a15215a 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -980,8 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
 		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
 	days = sd->Day;
 	month = sd->Month;
-	if ((days > 31) || (month > 12)) {
+	if (days > 31 || month < 1 || month > 12) {
 		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
+		if (month < 1)
+			month = 1;
 		if (month > 12)
 			month = 12;
 	}

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH] cifs: small underflow in cnvrtDosUnixTm()
@ 2017-04-10 13:49 ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-04-10 13:49 UTC (permalink / raw)
  To: Steve French
  Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

January is month 1.  There is no zero-th month.  We don't care very much
if the days are invalid but for months, we use it to read from an array
so this bug means we read one space before the start of the
total_days_of_prev_months[] array.

Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index abae6dd2c6b9..f1f64a15215a 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -980,8 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
 		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
 	days = sd->Day;
 	month = sd->Month;
-	if ((days > 31) || (month > 12)) {
+	if (days > 31 || month < 1 || month > 12) {
 		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
+		if (month < 1)
+			month = 1;
 		if (month > 12)
 			month = 12;
 	}

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
  2017-04-10 13:49 ` Dan Carpenter
@ 2017-04-28 12:51   ` Dan Carpenter
  -1 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-04-28 12:51 UTC (permalink / raw)
  To: Steve French
  Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

January is month 1.  There is no zero-th month.  If someone passes a
zero month then it means we read from one space before the start of the
total_days_of_prev_months[] array.

We may as well also be strict about days as well.

Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
Signed-off-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
v2:  Be strict about days as well.  My first patch was less intrusive
because it only prevented the out of bounds access.  I have no idea how
common it is to pass in an illegal day but, hopefully, not very common.

diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index abae6dd2c6b9..4b2726ee4fad 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -980,10 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
 		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
 	days = sd->Day;
 	month = sd->Month;
-	if ((days > 31) || (month > 12)) {
+	if (days < 1 || days > 31 || month < 1 || month > 12) {
 		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
-		if (month > 12)
-			month = 12;
+		days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
+		month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
 	}
 	month -= 1;
 	days += total_days_of_prev_months[month];

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
@ 2017-04-28 12:51   ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-04-28 12:51 UTC (permalink / raw)
  To: Steve French
  Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

January is month 1.  There is no zero-th month.  If someone passes a
zero month then it means we read from one space before the start of the
total_days_of_prev_months[] array.

We may as well also be strict about days as well.

Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2:  Be strict about days as well.  My first patch was less intrusive
because it only prevented the out of bounds access.  I have no idea how
common it is to pass in an illegal day but, hopefully, not very common.

diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index abae6dd2c6b9..4b2726ee4fad 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -980,10 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
 		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
 	days = sd->Day;
 	month = sd->Month;
-	if ((days > 31) || (month > 12)) {
+	if (days < 1 || days > 31 || month < 1 || month > 12) {
 		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
-		if (month > 12)
-			month = 12;
+		days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
+		month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
 	}
 	month -= 1;
 	days += total_days_of_prev_months[month];

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
  2017-04-28 12:51   ` Dan Carpenter
@ 2017-04-28 14:40     ` walter harms
  -1 siblings, 0 replies; 12+ messages in thread
From: walter harms @ 2017-04-28 14:40 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Steve French, linux-cifs, samba-technical, kernel-janitors



Am 28.04.2017 14:51, schrieb Dan Carpenter:
> January is month 1.  There is no zero-th month.  If someone passes a
> zero month then it means we read from one space before the start of the
> total_days_of_prev_months[] array.
> 
> We may as well also be strict about days as well.
> 
> Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2:  Be strict about days as well.  My first patch was less intrusive
> because it only prevented the out of bounds access.  I have no idea how
> common it is to pass in an illegal day but, hopefully, not very common.
> 
> diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
> index abae6dd2c6b9..4b2726ee4fad 100644
> --- a/fs/cifs/netmisc.c
> +++ b/fs/cifs/netmisc.c
> @@ -980,10 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
>  		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
>  	days = sd->Day;
>  	month = sd->Month;
> -	if ((days > 31) || (month > 12)) {
> +	if (days < 1 || days > 31 || month < 1 || month > 12) {
>  		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
> -		if (month > 12)
> -			month = 12;
> +		days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
> +		month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
>  	}
>  	month -= 1;
>  	days += total_days_of_prev_months[month];

The mixing in now a bit unfortunate ... why not simply

	if (days < 1 || days > 31 || month < 1 || month > 12)
		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);

	month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
	days = (days < 1) ? 1 : ((days <= 31) ? days : 31);

	
hope that helps,
re,
 wh


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
@ 2017-04-28 14:40     ` walter harms
  0 siblings, 0 replies; 12+ messages in thread
From: walter harms @ 2017-04-28 14:40 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Steve French, linux-cifs, samba-technical, kernel-janitors



Am 28.04.2017 14:51, schrieb Dan Carpenter:
> January is month 1.  There is no zero-th month.  If someone passes a
> zero month then it means we read from one space before the start of the
> total_days_of_prev_months[] array.
> 
> We may as well also be strict about days as well.
> 
> Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2:  Be strict about days as well.  My first patch was less intrusive
> because it only prevented the out of bounds access.  I have no idea how
> common it is to pass in an illegal day but, hopefully, not very common.
> 
> diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
> index abae6dd2c6b9..4b2726ee4fad 100644
> --- a/fs/cifs/netmisc.c
> +++ b/fs/cifs/netmisc.c
> @@ -980,10 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
>  		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
>  	days = sd->Day;
>  	month = sd->Month;
> -	if ((days > 31) || (month > 12)) {
> +	if (days < 1 || days > 31 || month < 1 || month > 12) {
>  		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
> -		if (month > 12)
> -			month = 12;
> +		days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
> +		month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
>  	}
>  	month -= 1;
>  	days += total_days_of_prev_months[month];

The mixing in now a bit unfortunate ... why not simply

	if (days < 1 || days > 31 || month < 1 || month > 12)
		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);

	month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
	days = (days < 1) ? 1 : ((days <= 31) ? days : 31);

	
hope that helps,
re,
 wh


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
       [not found]     ` <59035444.6090305-fPG8STNUNVg@public.gmane.org>
@ 2017-04-28 14:41         ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-04-28 14:41 UTC (permalink / raw)
  To: walter harms
  Cc: Steve French, linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

On Fri, Apr 28, 2017 at 04:40:04PM +0200, walter harms wrote:
> 
> 
> Am 28.04.2017 14:51, schrieb Dan Carpenter:
> > January is month 1.  There is no zero-th month.  If someone passes a
> > zero month then it means we read from one space before the start of the
> > total_days_of_prev_months[] array.
> > 
> > We may as well also be strict about days as well.
> > 
> > Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
> > Signed-off-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
> > ---
> > v2:  Be strict about days as well.  My first patch was less intrusive
> > because it only prevented the out of bounds access.  I have no idea how
> > common it is to pass in an illegal day but, hopefully, not very common.
> > 
> > diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
> > index abae6dd2c6b9..4b2726ee4fad 100644
> > --- a/fs/cifs/netmisc.c
> > +++ b/fs/cifs/netmisc.c
> > @@ -980,10 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
> >  		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
> >  	days = sd->Day;
> >  	month = sd->Month;
> > -	if ((days > 31) || (month > 12)) {
> > +	if (days < 1 || days > 31 || month < 1 || month > 12) {
> >  		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
> > -		if (month > 12)
> > -			month = 12;
> > +		days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
> > +		month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
> >  	}
> >  	month -= 1;
> >  	days += total_days_of_prev_months[month];
> 
> The mixing in now a bit unfortunate ... why not simply
> 
> 	if (days < 1 || days > 31 || month < 1 || month > 12)
> 		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
> 
> 	month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
> 	days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
> 

I prefer my version because I feel like it more closely expresses what
I want to say.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
@ 2017-04-28 14:41         ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-04-28 14:41 UTC (permalink / raw)
  To: walter harms
  Cc: Steve French, linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

On Fri, Apr 28, 2017 at 04:40:04PM +0200, walter harms wrote:
> 
> 
> Am 28.04.2017 14:51, schrieb Dan Carpenter:
> > January is month 1.  There is no zero-th month.  If someone passes a
> > zero month then it means we read from one space before the start of the
> > total_days_of_prev_months[] array.
> > 
> > We may as well also be strict about days as well.
> > 
> > Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > v2:  Be strict about days as well.  My first patch was less intrusive
> > because it only prevented the out of bounds access.  I have no idea how
> > common it is to pass in an illegal day but, hopefully, not very common.
> > 
> > diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
> > index abae6dd2c6b9..4b2726ee4fad 100644
> > --- a/fs/cifs/netmisc.c
> > +++ b/fs/cifs/netmisc.c
> > @@ -980,10 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
> >  		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
> >  	days = sd->Day;
> >  	month = sd->Month;
> > -	if ((days > 31) || (month > 12)) {
> > +	if (days < 1 || days > 31 || month < 1 || month > 12) {
> >  		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
> > -		if (month > 12)
> > -			month = 12;
> > +		days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
> > +		month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
> >  	}
> >  	month -= 1;
> >  	days += total_days_of_prev_months[month];
> 
> The mixing in now a bit unfortunate ... why not simply
> 
> 	if (days < 1 || days > 31 || month < 1 || month > 12)
> 		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
> 
> 	month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
> 	days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
> 

I prefer my version because I feel like it more closely expresses what
I want to say.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
  2017-04-28 14:41         ` Dan Carpenter
@ 2017-04-28 14:57           ` walter harms
  -1 siblings, 0 replies; 12+ messages in thread
From: walter harms @ 2017-04-28 14:57 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Steve French, linux-cifs, samba-technical, kernel-janitors



Am 28.04.2017 16:41, schrieb Dan Carpenter:
> On Fri, Apr 28, 2017 at 04:40:04PM +0200, walter harms wrote:
>>
>>
>> Am 28.04.2017 14:51, schrieb Dan Carpenter:
>>> January is month 1.  There is no zero-th month.  If someone passes a
>>> zero month then it means we read from one space before the start of the
>>> total_days_of_prev_months[] array.
>>>
>>> We may as well also be strict about days as well.
>>>
>>> Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>> ---
>>> v2:  Be strict about days as well.  My first patch was less intrusive
>>> because it only prevented the out of bounds access.  I have no idea how
>>> common it is to pass in an illegal day but, hopefully, not very common.
>>>
>>> diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
>>> index abae6dd2c6b9..4b2726ee4fad 100644
>>> --- a/fs/cifs/netmisc.c
>>> +++ b/fs/cifs/netmisc.c
>>> @@ -980,10 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
>>>  		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
>>>  	days = sd->Day;
>>>  	month = sd->Month;
>>> -	if ((days > 31) || (month > 12)) {
>>> +	if (days < 1 || days > 31 || month < 1 || month > 12) {
>>>  		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
>>> -		if (month > 12)
>>> -			month = 12;
>>> +		days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
>>> +		month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
>>>  	}
>>>  	month -= 1;
>>>  	days += total_days_of_prev_months[month];
>>
>> The mixing in now a bit unfortunate ... why not simply
>>
>> 	if (days < 1 || days > 31 || month < 1 || month > 12)
>> 		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
>>
>> 	month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
>> 	days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
>>
> 
> I prefer my version because I feel like it more closely expresses what
> I want to say.
> 

(Actually it is your code just without the braces.)
what is about differentiating between day and month ?

if (days < 1 || days > 31) {
		cifs_dbg(VFS, "illegal day: %d\n", days);
		days = (days < 1) ? 1 : 31 ;
		}


if ( month < 1 || month > 12) {
		cifs_dbg(VFS, "illegal month %d\n", month);
		month = (month < 1) ? 1 : 12 ;
		}

this way you have a obvious error handling for day and month.

I still like my first version even when day/month are recalculated every
time the flow is very linear only the error message is a deviation.
(Given that ?: makes it not easy to digest)

re,
 wh


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
@ 2017-04-28 14:57           ` walter harms
  0 siblings, 0 replies; 12+ messages in thread
From: walter harms @ 2017-04-28 14:57 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Steve French, linux-cifs, samba-technical, kernel-janitors



Am 28.04.2017 16:41, schrieb Dan Carpenter:
> On Fri, Apr 28, 2017 at 04:40:04PM +0200, walter harms wrote:
>>
>>
>> Am 28.04.2017 14:51, schrieb Dan Carpenter:
>>> January is month 1.  There is no zero-th month.  If someone passes a
>>> zero month then it means we read from one space before the start of the
>>> total_days_of_prev_months[] array.
>>>
>>> We may as well also be strict about days as well.
>>>
>>> Fixes: 1bd5bbcb6531 ("[CIFS] Legacy time handling for Win9x and OS/2 part 1")
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>> ---
>>> v2:  Be strict about days as well.  My first patch was less intrusive
>>> because it only prevented the out of bounds access.  I have no idea how
>>> common it is to pass in an illegal day but, hopefully, not very common.
>>>
>>> diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
>>> index abae6dd2c6b9..4b2726ee4fad 100644
>>> --- a/fs/cifs/netmisc.c
>>> +++ b/fs/cifs/netmisc.c
>>> @@ -980,10 +980,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
>>>  		cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
>>>  	days = sd->Day;
>>>  	month = sd->Month;
>>> -	if ((days > 31) || (month > 12)) {
>>> +	if (days < 1 || days > 31 || month < 1 || month > 12) {
>>>  		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
>>> -		if (month > 12)
>>> -			month = 12;
>>> +		days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
>>> +		month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
>>>  	}
>>>  	month -= 1;
>>>  	days += total_days_of_prev_months[month];
>>
>> The mixing in now a bit unfortunate ... why not simply
>>
>> 	if (days < 1 || days > 31 || month < 1 || month > 12)
>> 		cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
>>
>> 	month = (month < 1) ? 1 : ((month <= 12) ? month : 12);
>> 	days = (days < 1) ? 1 : ((days <= 31) ? days : 31);
>>
> 
> I prefer my version because I feel like it more closely expresses what
> I want to say.
> 

(Actually it is your code just without the braces.)
what is about differentiating between day and month ?

if (days < 1 || days > 31) {
		cifs_dbg(VFS, "illegal day: %d\n", days);
		days = (days < 1) ? 1 : 31 ;
		}


if ( month < 1 || month > 12) {
		cifs_dbg(VFS, "illegal month %d\n", month);
		month = (month < 1) ? 1 : 12 ;
		}

this way you have a obvious error handling for day and month.

I still like my first version even when day/month are recalculated every
time the flow is very linear only the error message is a deviation.
(Given that ?: makes it not easy to digest)

re,
 wh


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
       [not found]           ` <59035861.8050101-fPG8STNUNVg@public.gmane.org>
@ 2017-04-29 18:49               ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-04-29 18:49 UTC (permalink / raw)
  To: walter harms
  Cc: Steve French, linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

I will resend on Monday.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] cifs: small underflow in cnvrtDosUnixTm()
@ 2017-04-29 18:49               ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-04-29 18:49 UTC (permalink / raw)
  To: walter harms
  Cc: Steve French, linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

I will resend on Monday.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-04-29 18:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10 13:49 [PATCH] cifs: small underflow in cnvrtDosUnixTm() Dan Carpenter
2017-04-10 13:49 ` Dan Carpenter
2017-04-28 12:51 ` [PATCH v2] " Dan Carpenter
2017-04-28 12:51   ` Dan Carpenter
2017-04-28 14:40   ` walter harms
2017-04-28 14:40     ` walter harms
     [not found]     ` <59035444.6090305-fPG8STNUNVg@public.gmane.org>
2017-04-28 14:41       ` Dan Carpenter
2017-04-28 14:41         ` Dan Carpenter
2017-04-28 14:57         ` walter harms
2017-04-28 14:57           ` walter harms
     [not found]           ` <59035861.8050101-fPG8STNUNVg@public.gmane.org>
2017-04-29 18:49             ` Dan Carpenter
2017-04-29 18:49               ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.