Fix for issue #20

Reject NuDateTime structs with invalid fields.  Passing bogus values
to the ATL CTime constructor does bad things.
This commit is contained in:
Andy McFadden 2017-09-21 12:20:16 -07:00
parent a8c2e4cfd6
commit 8e326f2f62
3 changed files with 16 additions and 3 deletions

View File

@ -1,5 +1,5 @@
End-User License Agreement for CiderPress End-User License Agreement for CiderPress
Copyright (c) 2016, CiderPress project authors Copyright (C) 2017, CiderPress project authors
All rights reserved. All rights reserved.
AGREEMENT. After reading this agreement carefully, if you ("Customer") do AGREEMENT. After reading this agreement carefully, if you ("Customer") do

View File

@ -835,6 +835,7 @@ NuResult NufxArchive::ContentFunc(NuArchive* pArchive, void* vpRecord)
pDateTime->extra == 0 && pDateTime->extra == 0 &&
pDateTime->weekDay == 0) pDateTime->weekDay == 0)
{ {
// not invalid; just no date set
return kDateNone; return kDateNone;
} }
@ -858,8 +859,17 @@ NuResult NufxArchive::ContentFunc(NuArchive* pArchive, void* vpRecord)
//LOGI(" Ignoring funky year %ld", year); //LOGI(" Ignoring funky year %ld", year);
return kDateInvalid; return kDateInvalid;
} }
if (pDateTime->month > 11)
// Must range-check values before passing them to CTime constructor, which
// now throws a remarkably fatal exception.
if (pDateTime->month > 11 || // [0,11]
pDateTime->day > 30 || // [0,30]
pDateTime->hour > 59 || // [0,59]
pDateTime->minute > 59 || // [0,59]
pDateTime->second > 59) { // [0,59]
return kDateInvalid; return kDateInvalid;
}
CTime modTime(year, CTime modTime(year,
pDateTime->month+1, pDateTime->month+1,
@ -867,7 +877,8 @@ NuResult NufxArchive::ContentFunc(NuArchive* pArchive, void* vpRecord)
pDateTime->hour, pDateTime->hour,
pDateTime->minute, pDateTime->minute,
pDateTime->second); pDateTime->second);
return (time_t) modTime.GetTime(); time_t result = (time_t)modTime.GetTime();
return result;
} }
/*static*/ NuResult NufxArchive::ArrayDeleteHandler(NuArchive* pArchive, void* ptr) /*static*/ NuResult NufxArchive::ArrayDeleteHandler(NuArchive* pArchive, void* ptr)

View File

@ -1,3 +1,5 @@
2017/09/21 ***** v3.1.0 shipped *****
2016/01/11 fadden 2016/01/11 fadden
- Fix handling of disk images (broken by previous change). - Fix handling of disk images (broken by previous change).