From b38e4a4332bf8ce088dee679bc8e573e6502fcf8 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 16 Jan 2022 19:27:55 -0800 Subject: [PATCH] Fixed a few cases where we were not checking GetStrData properly. --- python/message.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/message.c b/python/message.c index 5de428a2b5..9bede8d42b 100644 --- a/python/message.c +++ b/python/message.c @@ -926,8 +926,9 @@ __attribute__((flatten)) static PyObject* PyUpb_CMessage_GetAttr( // to pick up class attributes. But we have to special-case "Extensions" // which affirmatively returns AttributeError when a message is not // extendable. + const char* name; if (PyErr_ExceptionMatches(PyExc_AttributeError) && - strcmp(PyUpb_GetStrData(attr), "Extensions") != 0) { + (name = PyUpb_GetStrData(attr)) && strcmp(name, "Extensions") != 0) { PyErr_Clear(); return PyUpb_MessageMeta_GetAttr((PyObject*)Py_TYPE(_self), attr); } @@ -1720,6 +1721,7 @@ void PyUpb_MessageMeta_AddFieldNumber(PyObject* self, const upb_FieldDef* f) { static PyObject* PyUpb_MessageMeta_GetDynamicAttr(PyObject* self, PyObject* name) { const char* name_buf = PyUpb_GetStrData(name); + if (!name_buf) return NULL; const upb_MessageDef* msgdef = PyUpb_MessageMeta_GetMsgdef(self); const upb_FileDef* filedef = upb_MessageDef_File(msgdef); const upb_DefPool* symtab = upb_FileDef_Pool(filedef);