]> granicus.if.org Git - python/commitdiff
ensure internal buffer is large enough for string after flushing (closes #24481)
authorBenjamin Peterson <benjamin@python.org>
Sat, 27 Jun 2015 19:52:41 +0000 (14:52 -0500)
committerBenjamin Peterson <benjamin@python.org>
Sat, 27 Jun 2015 19:52:41 +0000 (14:52 -0500)
Lib/test/test_hotshot.py
Misc/NEWS
Modules/_hotshot.c

index 7da9746d789e2e3e55f0a28dea4c65b58217d921..9f4b798a6972f1e1ce944494e407f15a1fe3d0d0 100644 (file)
@@ -149,6 +149,10 @@ class HotShotTestCase(unittest.TestCase):
         stats.load(self.logfn)
         os.unlink(self.logfn)
 
+    def test_large_info(self):
+        p = self.new_profiler()
+        self.assertRaises(ValueError, p.addinfo, "A", "A" * 0xfceb)
+
 
 def test_main():
     test_support.run_unittest(HotShotTestCase)
index 3b9b3fad1ddc2e64db2b6af75554534e7cea4ef3..1496398bb130a654f365706254c8cab971903b49 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -30,6 +30,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #24481: Fix possible memory corruption with large profiler info strings
+  in hotshot.
+
 - Issue #24489: ensure a previously set C errno doesn't disturb cmath.polar().
 
 - Issue #19543: io.TextIOWrapper (and hence io.open()) now uses the internal
index df8a7f94cd4ba03eba7d4c160d449d830841b784..9719cb76733be675c150af40da994c4a9296ad5b 100644 (file)
@@ -626,6 +626,10 @@ pack_string(ProfilerObject *self, const char *s, Py_ssize_t len)
     if (len + PISIZE + self->index >= BUFFERSIZE) {
         if (flush_data(self) < 0)
             return -1;
+        if (len + PISIZE + self->index >= BUFFERSIZE) {
+            PyErr_SetString(PyExc_ValueError, "string too large for internal buffer");
+            return -1;
+        }
     }
     assert(len < INT_MAX);
     if (pack_packed_int(self, (int)len) < 0)