updaterecord-py.c: Fix SIGSEGV during date-time parsing (#72)
authorTomas Mlcoch <tmlcoch@redhat.com>
Tue, 31 Jan 2017 09:07:14 +0000 (10:07 +0100)
committerTomas Mlcoch <tmlcoch@redhat.com>
Tue, 31 Jan 2017 09:07:14 +0000 (10:07 +0100)
src/python/updaterecord-py.c

index 6c5a4fd41b8637c9e3d2fcdd656a27c9c45078b6..4ea4094739fb9f346f0f0a4407e52b52a18678ef 100644 (file)
@@ -272,14 +272,14 @@ get_datetime(_UpdateRecordObject *self, void *member_offset)
     if (str == NULL)
         Py_RETURN_NONE;
 
-    struct tm *dt = malloc(sizeof(struct tm));
+    struct tm *dt = g_malloc0(sizeof(struct tm));
     char *res = strptime(str, "%Y-%m-%d %H:%M:%S", dt);
     if (res == NULL) {
-        memset(res,0,sizeof(dt));
+        memset(dt, 0, sizeof(struct tm));
         res = strptime(str, "%Y-%m-%d", dt);
         if (res == NULL)
            PyErr_SetString(CrErr_Exception, "Invalid date");
-        }
+    }
     PyObject *py_dt = PyDateTime_FromDateAndTime(dt->tm_year + 1900,
                                       dt->tm_mon + 1, dt->tm_mday,
                                       dt->tm_hour, dt->tm_min, dt->tm_sec, 0);