From: Tomas Mlcoch Date: Tue, 31 Jan 2017 09:07:14 +0000 (+0100) Subject: updaterecord-py.c: Fix SIGSEGV during date-time parsing (#72) X-Git-Tag: upstream/0.10.0~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04828e628a970d15f0286712a4b37f7af6a75560;p=services%2Fcreaterepo_c.git updaterecord-py.c: Fix SIGSEGV during date-time parsing (#72) --- diff --git a/src/python/updaterecord-py.c b/src/python/updaterecord-py.c index 6c5a4fd..4ea4094 100644 --- a/src/python/updaterecord-py.c +++ b/src/python/updaterecord-py.c @@ -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);