[file-roller] Prevent a NULL pointer deref in mktime_from_string(). It's possible to call mktime_from_string() wit
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller] Prevent a NULL pointer deref in mktime_from_string(). It's possible to call mktime_from_string() wit
- Date: Mon, 23 May 2011 17:35:38 +0000 (UTC)
commit 2899c092f249a4fa822a896baf128b6c8c75b634
Author: Jasper Lievisse Adriaanse <jasper humppa nl>
Date: Mon May 23 13:11:30 2011 +0200
Prevent a NULL pointer deref in mktime_from_string(). It's possible to call mktime_from_string() with NULL arguments for day, month and year. This would in turn lead to calling atoi(NULL), which leads to a crash.
So instead fill in any NULL values with the corresponding unit from Jan 1st 1970.
src/fr-command-rpm.c | 41 +++++++++++++++++++++++++----------------
1 files changed, 25 insertions(+), 16 deletions(-)
---
diff --git a/src/fr-command-rpm.c b/src/fr-command-rpm.c
index c0560c5..c5bec5c 100644
--- a/src/fr-command-rpm.c
+++ b/src/fr-command-rpm.c
@@ -61,23 +61,32 @@ mktime_from_string (char *month,
tm.tm_mon = i;
break;
}
- }
- tm.tm_mday = atoi (mday);
- if (strchr (year, ':') != NULL) {
- char **fields = g_strsplit (year, ":", 2);
- if (n_fields (fields) == 2) {
- time_t now;
- struct tm *now_tm;
-
- tm.tm_hour = atoi (fields[0]);
- tm.tm_min = atoi (fields[1]);
-
- now = time(NULL);
- now_tm = localtime (&now);
- tm.tm_year = now_tm->tm_year;
- }
} else
- tm.tm_year = atoi (year) - 1900;
+ tm.tm_mon = 0;
+
+ if (mday != NULL)
+ tm.tm_mday = atoi (mday);
+ else
+ tm.tm_mday = 1;
+
+ if (year != NULL) {
+ if (strchr (year, ':') != NULL) {
+ char **fields = g_strsplit (year, ":", 2);
+ if (n_fields (fields) == 2) {
+ time_t now;
+ struct tm *now_tm;
+
+ tm.tm_hour = atoi (fields[0]);
+ tm.tm_min = atoi (fields[1]);
+
+ now = time(NULL);
+ now_tm = localtime (&now);
+ tm.tm_year = now_tm->tm_year;
+ }
+ } else
+ tm.tm_year = atoi (year) - 1900;
+ } else
+ tm.tm_year = 70;
return mktime (&tm);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]