aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/utils
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2019-08-20 07:56:44 +0200
committerRoland Knall <rknall@gmail.com>2019-08-20 10:52:18 +0000
commitd4ddf3d8bbd7531075d9d85e1839b63afb90dc01 (patch)
tree0011694afb39595de2dff2791a7842731a89b0fd /ui/qt/utils
parenteabd1b0abb38fdd92147fba8a9030fe0bcd8fc6a (diff)
Qt: Fix null pointer dereference
Rework existing code to avoid unsafe localtime Change-Id: I266ae7e006c6aeed42af39fea07c888874d0f588 Reviewed-on: https://code.wireshark.org/review/34329 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/utils')
-rw-r--r--ui/qt/utils/wireshark_zip_helper.cpp62
1 files changed, 17 insertions, 45 deletions
diff --git a/ui/qt/utils/wireshark_zip_helper.cpp b/ui/qt/utils/wireshark_zip_helper.cpp
index 88e13cf098..f2035dda53 100644
--- a/ui/qt/utils/wireshark_zip_helper.cpp
+++ b/ui/qt/utils/wireshark_zip_helper.cpp
@@ -148,58 +148,30 @@ bool WireSharkZipHelper::unzip(QString zipFile, QString directory, bool (*fileCh
#define UINT32_MAX (0xffffffff)
#endif
-/* The following methods are being taken from https://github.com/nmoinvaz/minizip/blob/1.2/minishared.c */
-int invalid_date(const struct tm *ptm)
+unsigned long qDateToDosDate(QDateTime time)
{
-#define datevalue_in_range(min, max, value) ((min) <= (value) && (value) <= (max))
- return (!datevalue_in_range(0, 207, ptm->tm_year) ||
- !datevalue_in_range(0, 11, ptm->tm_mon) ||
- !datevalue_in_range(1, 31, ptm->tm_mday) ||
- !datevalue_in_range(0, 23, ptm->tm_hour) ||
- !datevalue_in_range(0, 59, ptm->tm_min) ||
- !datevalue_in_range(0, 59, ptm->tm_sec));
-#undef datevalue_in_range
-}
+ QDate ld = time.toLocalTime().date();
-uint32_t tm_to_dosdate(const struct tm *ptm)
-{
- struct tm fixed_tm;
-
- /* Years supported:
- * [00, 79] (assumed to be between 2000 and 2079)
- * [80, 207] (assumed to be between 1980 and 2107, typical output of old
- software that does 'year-1900' to get a double digit year)
- * [1980, 2107] (due to the date format limitations, only years between 1980 and 2107 can be stored.)
- */
-
- memcpy(&fixed_tm, ptm, sizeof(struct tm));
- if (fixed_tm.tm_year >= 1980) /* range [1980, 2107] */
- fixed_tm.tm_year -= 1980;
- else if (fixed_tm.tm_year >= 80) /* range [80, 99] */
- fixed_tm.tm_year -= 80;
- else /* range [00, 79] */
- fixed_tm.tm_year += 20;
-
- if (invalid_date(ptm))
- return 0;
+ int year = ld.year() - 1900;
+ if ( year >= 1980 )
+ year -= 1980;
+ else if ( year >= 80 )
+ year -= 80;
+ else
+ year += 20;
- return (uint32_t)(((fixed_tm.tm_mday) + (32 * (fixed_tm.tm_mon + 1)) + (512 * fixed_tm.tm_year)) << 16) |
- ((fixed_tm.tm_sec / 2) + (32 * fixed_tm.tm_min) + (2048 * (uint32_t)fixed_tm.tm_hour));
-}
+ int month = ld.month() - 1;
+ int day = ld.day();
-unsigned long qDateToDosDate(QDateTime time)
-{
- time_t rawtime = time.toTime_t();
- struct tm * timeinfo;
+ if ( year < 0 || year > 207 || month < 1 || month > 31 )
+ return 0;
- timeinfo = localtime(&rawtime);
- timeinfo->tm_year = time.date().year() - 1900;
- timeinfo->tm_mon = time.date().month() - 1;
- timeinfo->tm_mday = time.date().day();
+ QTime lt = time.toLocalTime().time();
- mktime(timeinfo);
+ unsigned int dosDate = static_cast<unsigned int>((day + (32 * (month + 1)) + (512 * year)));
+ unsigned int dosTime = static_cast<unsigned int>((lt.second() / 2) + (32 * lt.minute()) + (2048 * lt.hour()));
- return tm_to_dosdate(timeinfo);
+ return dosDate << 16 | dosTime;
}
void WireSharkZipHelper::addFileToZip(zipFile zf, QString filepath, QString fileInZip)