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 <ideasman42@gmail.com>2014-02-22 10:54:50 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-02-22 10:54:50 +0400
commit99edd29835fca6128ff05cc1e67885448eadc62d (patch)
tree23739e07697e321c8cf004ab63edc2d8c0ab6787 /source/blender/python
parent739ae1d80956759767e137fe17286dc360788a1b (diff)
Fix T38753: Python script paths weren't escaped (Win only)
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_interface.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 23486a8ab91..cf5bf3aca9c 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -496,15 +496,19 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
* incompatible'.
* So now we load the script file data to a buffer */
{
- char *pystring;
+ PyObject *py_dict_local, *fn_py;
+ const char *pystring = "with open(fn, 'r') as f: exec(f.read())";
fclose(fp);
- pystring = MEM_mallocN(strlen(fn) + 37, "pystring");
- pystring[0] = '\0';
- sprintf(pystring, "f=open(r'%s');exec(f.read());f.close()", fn);
- py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict);
- MEM_freeN(pystring);
+ py_dict_local = PyDict_New();
+ fn_py = PyC_UnicodeFromByte(fn);
+ PyDict_SetItemString(py_dict_local, "fn", fn_py);
+ Py_DECREF(fn_py);
+
+ py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict_local);
+
+ Py_DECREF(py_dict_local);
}
#else
py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);