summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-07-25 22:00:30 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-07-25 22:00:30 (GMT)
commita22d8231a3821e3b11c2153bef7970fb260e6860 (patch)
tree2bdb4c696f9ff39032b7fc8445b0e81526e51688
parent19e020c5c713fcf24d66d72f5e599d57e8841360 (diff)
parent5a2146a2fdb9b8adf6472f1bedbba68c41bab232 (diff)
downloadcpython-a22d8231a3821e3b11c2153bef7970fb260e6860.zip
cpython-a22d8231a3821e3b11c2153bef7970fb260e6860.tar.gz
cpython-a22d8231a3821e3b11c2153bef7970fb260e6860.tar.bz2
merge
-rw-r--r--Lib/test/datetimetester.py11
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_datetimemodule.c14
4 files changed, 22 insertions, 7 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index b8c6138..34a8d63 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -5,6 +5,7 @@ See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
import sys
import pickle
+import random
import unittest
from operator import lt, le, gt, ge, eq, ne, truediv, floordiv, mod
@@ -76,8 +77,18 @@ class PicklableFixedOffset(FixedOffset):
def __init__(self, offset=None, name=None, dstoffset=None):
FixedOffset.__init__(self, offset, name, dstoffset)
+class _TZInfo(tzinfo):
+ def utcoffset(self, datetime_module):
+ return random.random()
+
class TestTZInfo(unittest.TestCase):
+ def test_refcnt_crash_bug_22044(self):
+ tz1 = _TZInfo()
+ dt1 = datetime(2014, 7, 21, 11, 32, 3, 0, tz1)
+ with self.assertRaises(TypeError):
+ dt1.utcoffset()
+
def test_non_abstractness(self):
# In order to allow subclasses to get pickled, the C implementation
# wasn't able to get away with having __init__ raise
diff --git a/Misc/ACKS b/Misc/ACKS
index 4a68015..c1c29d2 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -411,6 +411,7 @@ Russell Finn
Dan Finnie
Nils Fischbeck
Frederik Fix
+Tom Flanagan
Matt Fleming
Hernán Martínez Foffani
Artem Fokin
diff --git a/Misc/NEWS b/Misc/NEWS
index 7059888..b120f70 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -117,6 +117,9 @@ Library
- Issue #16133: The asynchat.async_chat.handle_read() method now ignores
BlockingIOError exceptions.
+- Issue #22044: Fixed premature DECREF in call_tzinfo_method.
+ Patch by Tom Flanagan.
+
- Issue #19884: readline: Disable the meta modifier key if stdout is not
a terminal to not write the ANSI sequence "\033[1034h" into stdout. This
sequence is used on some terminal (ex: TERM=xterm-256color") to enable
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 04d9b5d..701c587 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -897,11 +897,11 @@ call_tzinfo_method(PyObject *tzinfo, char *name, PyObject *tzinfoarg)
}
}
else {
- Py_DECREF(offset);
PyErr_Format(PyExc_TypeError,
"tzinfo.%s() must return None or "
"timedelta, not '%.200s'",
name, Py_TYPE(offset)->tp_name);
+ Py_DECREF(offset);
return NULL;
}
@@ -2153,7 +2153,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
* is odd. Note that x is odd when it's last bit is 1. The
* code below uses bitwise and operation to check the last
* bit. */
- temp = PyNumber_And(x, one); /* temp <- x & 1 */
+ temp = PyNumber_And(x, one); /* temp <- x & 1 */
if (temp == NULL) {
Py_DECREF(x);
goto Done;
@@ -3224,10 +3224,10 @@ timezone_richcompare(PyDateTime_TimeZone *self,
if (op != Py_EQ && op != Py_NE)
Py_RETURN_NOTIMPLEMENTED;
if (Py_TYPE(other) != &PyDateTime_TimeZoneType) {
- if (op == Py_EQ)
- Py_RETURN_FALSE;
- else
- Py_RETURN_TRUE;
+ if (op == Py_EQ)
+ Py_RETURN_FALSE;
+ else
+ Py_RETURN_TRUE;
}
return delta_richcompare(self->offset, other->offset, op);
}
@@ -4778,7 +4778,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
static char *keywords[] = {"tz", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:astimezone", keywords,
- &tzinfo))
+ &tzinfo))
return NULL;
if (check_tzinfo_subclass(tzinfo) == -1)