Fix accessing an empty context succeeding when it shouldn't

Internally an empty string is used to access context member `__dir__`,
which caused `getattr(context, "")` to succeed returning None.
This commit is contained in:
Campbell Barton 2022-04-06 11:42:45 +10:00
parent f208713b02
commit 5d31252c76
1 changed files with 11 additions and 1 deletions

View File

@ -4210,7 +4210,17 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname)
ListBase newlb;
short newtype;
const eContextResult done = CTX_data_get(C, name, &newptr, &newlb, &newtype);
/* An empty string is used to implement #CTX_data_dir_get,
* without this check `getattr(context, "")` succeeds. */
eContextResult done;
if (name[0]) {
done = CTX_data_get(C, name, &newptr, &newlb, &newtype);
}
else {
/* Fall through to built-in `getattr`. */
done = CTX_RESULT_MEMBER_NOT_FOUND;
BLI_listbase_clear(&newlb);
}
if (done == CTX_RESULT_OK) {
switch (newtype) {