mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 11:49:12 +00:00 
			
		
		
		
	Issue #18408: type_new() and PyType_FromSpecWithBases() now raise MemoryError
on memory allocation failure
This commit is contained in:
		
							parent
							
								
									e699e5a218
								
							
						
					
					
						commit
						53510cda59
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -2292,8 +2292,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
 | 
				
			||||||
            /* Silently truncate the docstring if it contains null bytes. */
 | 
					            /* Silently truncate the docstring if it contains null bytes. */
 | 
				
			||||||
            len = strlen(doc_str);
 | 
					            len = strlen(doc_str);
 | 
				
			||||||
            tp_doc = (char *)PyObject_MALLOC(len + 1);
 | 
					            tp_doc = (char *)PyObject_MALLOC(len + 1);
 | 
				
			||||||
            if (tp_doc == NULL)
 | 
					            if (tp_doc == NULL) {
 | 
				
			||||||
 | 
					                PyErr_NoMemory();
 | 
				
			||||||
                goto error;
 | 
					                goto error;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            memcpy(tp_doc, doc_str, len + 1);
 | 
					            memcpy(tp_doc, doc_str, len + 1);
 | 
				
			||||||
            type->tp_doc = tp_doc;
 | 
					            type->tp_doc = tp_doc;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -2496,8 +2498,10 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
 | 
				
			||||||
        if (slot->slot == Py_tp_doc) {
 | 
					        if (slot->slot == Py_tp_doc) {
 | 
				
			||||||
            size_t len = strlen(slot->pfunc)+1;
 | 
					            size_t len = strlen(slot->pfunc)+1;
 | 
				
			||||||
            char *tp_doc = PyObject_MALLOC(len);
 | 
					            char *tp_doc = PyObject_MALLOC(len);
 | 
				
			||||||
            if (tp_doc == NULL)
 | 
					            if (tp_doc == NULL) {
 | 
				
			||||||
 | 
					                PyErr_NoMemory();
 | 
				
			||||||
                goto fail;
 | 
					                goto fail;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            memcpy(tp_doc, slot->pfunc, len);
 | 
					            memcpy(tp_doc, slot->pfunc, len);
 | 
				
			||||||
            type->tp_doc = tp_doc;
 | 
					            type->tp_doc = tp_doc;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue