]> granicus.if.org Git - python/commitdiff
Issue #21951: Use attemptckalloc() instead of ckalloc() in Tkinter.
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 11 Sep 2014 07:40:44 +0000 (10:40 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 11 Sep 2014 07:40:44 +0000 (10:40 +0300)
ckalloc() causes the Tcl interpreter to panic, attemptckalloc() returns NULL
if the memory allocation fails.

1  2 
Misc/NEWS
Modules/_tkinter.c

diff --cc Misc/NEWS
index 49909a103b5a6afd8f0cff25b38b9156e13bc6ac,666887773bc1cdc4e37161a5ce8257b5963e7c7f..079a0eb6a57be37882f87ca7e0419b1e1fa0e1ce
+++ b/Misc/NEWS
@@@ -132,17 -32,11 +132,20 @@@ Core and Builtin
  Library
  -------
  
+ - Issue #21951: Tkinter now most likely raises MemoryError instead of crash
+   if the memory allocation fails.
  - Issue #22338: Fix a crash in the json module on memory allocation failure.
  
 +- Issue #12410: imaplib.IMAP4 now supports the context management protocol.
 +  Original patch by Tarek Ziadé.
 +
 +- Issue #16662: load_tests() is now unconditionally run when it is present in
 +  a package's __init__.py.  TestLoader.loadTestsFromModule() still accepts
 +  use_load_tests, but it is deprecated and ignored.  A new keyword-only
 +  attribute `pattern` is added and documented.  Patch given by Robert Collins,
 +  tweaked by Barry Warsaw.
 +
  - Issue #22226: First letter no longer is stripped from the "status" key in
    the result of Treeview.heading().
  
index d54ebb47a35cf253197c639b67265d6e00c06ea2,7871dec8d4186a35436dec5f4aab578c109085af..a8e6d9828ce4d0eadc353294977dd6b18433ae43
@@@ -905,21 -898,17 +905,21 @@@ AsObj(PyObject *value
          Tcl_Obj **argv;
          Py_ssize_t size, i;
  
 -        size = PyTuple_Size(value);
 +        size = PySequence_Fast_GET_SIZE(value);
          if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) {
 -            PyErr_SetString(PyExc_OverflowError, "tuple is too long");
 +            PyErr_SetString(PyExc_OverflowError,
 +                            PyTuple_Check(value) ? "tuple is too long" :
 +                                                   "list is too long");
              return NULL;
          }
-         argv = (Tcl_Obj **) ckalloc(((size_t)size) * sizeof(Tcl_Obj *));
+         argv = (Tcl_Obj **) attemptckalloc(((size_t)size) * sizeof(Tcl_Obj *));
 -        if(!argv)
 -          return 0;
 +        if(!argv) {
 +          PyErr_NoMemory();
 +          return NULL;
 +        }
          for (i = 0; i < size; i++)
 -          argv[i] = AsObj(PyTuple_GetItem(value,i));
 -        result = Tcl_NewListObj(PyTuple_Size(value), argv);
 +          argv[i] = AsObj(PySequence_Fast_GET_ITEM(value,i));
 +        result = Tcl_NewListObj(size, argv);
          ckfree(FREECAST argv);
          return result;
      }
@@@ -1106,12 -1095,10 +1106,12 @@@ Tkapp_CallArgs(PyObject *args, Tcl_Obj*
  
          if (objc > ARGSZ) {
              if (!CHECK_SIZE(objc, sizeof(Tcl_Obj *))) {
 -                PyErr_SetString(PyExc_OverflowError, "tuple is too long");
 +                PyErr_SetString(PyExc_OverflowError,
 +                                PyTuple_Check(args) ? "tuple is too long" :
 +                                                      "list is too long");
                  return NULL;
              }
-             objv = (Tcl_Obj **)ckalloc(((size_t)objc) * sizeof(Tcl_Obj *));
+             objv = (Tcl_Obj **)attemptckalloc(((size_t)objc) * sizeof(Tcl_Obj *));
              if (objv == NULL) {
                  PyErr_NoMemory();
                  objc = 0;