Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-04-06 04:42:45 +0300
committerCampbell Barton <campbell@blender.org>2022-04-06 04:47:43 +0300
commit5d31252c762b35a5af3d668f45dccf5bb397627e (patch)
tree8b67528e7addd06862fdb6253c0cdaba9c397d97
parentf208713b02a3251be2463dfda9e833da5cb42ccd (diff)
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.
-rw-r--r--source/blender/python/intern/bpy_rna.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index bb212bfcccc..a28137c3bed 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -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) {