From e48a649b43cec37bc177da9aa41e23371d0c154b Mon Sep 17 00:00:00 2001
From: Aurelien Aptel <aaptel@suse.com>
Date: Mon, 12 Jun 2017 12:45:11 -0600
Subject: [PATCH] cifs: small underflow in cnvrtDosUnixTm() (bnc#1043935).
Patch-mainline: v4.12-rc1
Git-commit: 564277eceeca01e02b1ef3e141cfb939184601b4
References: bsc#1043935

    cifs: small underflow in cnvrtDosUnixTm()
    
    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>
    Signed-off-by: Steve French <smfrench@gmail.com>

Signed-off-by: Aurelien Aptel <aaptel@suse.com>

---
 fs/cifs/netmisc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index 73e47e84b61a..3732f79bc067 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -974,10 +974,10 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
 		cERROR(1, "illegal hours %d", st->Hours);
 	days = sd->Day;
 	month = sd->Month;
-	if ((days > 31) || (month > 12)) {
+	if (days < 1 || days > 31 || month < 1 || month > 12) {
 		cERROR(1, "illegal date, month %d day: %d", month, days);
-		if (month > 12)
-			month = 12;
+		days = clamp(days, 1, 31);
+		month = clamp(month, 1, 12);
 	}
 	month -= 1;
 	days += total_days_of_prev_months[month];
-- 
2.12.3

