##// END OF EJS Templates
fuzz: fix an unused result on getcwd() in pyutil...
Augie Fackler -
r44246:f6c0b051 default draft
parent child Browse files
Show More
@@ -1,49 +1,54
1 1 #include "pyutil.h"
2 2
3 #include <iostream>
3 4 #include <string>
4 5
5 6 namespace contrib
6 7 {
7 8
8 9 static char cpypath[8192] = "\0";
9 10
10 11 static PyObject *mainmod;
11 12 static PyObject *globals;
12 13
13 14 /* TODO: use Python 3 for this fuzzing? */
14 15 PyMODINIT_FUNC initparsers(void);
15 16
16 17 void initpy(const char *cselfpath)
17 18 {
18 19 const std::string subdir = "/sanpy/lib/python2.7";
19 20 /* HACK ALERT: we need a full Python installation built without
20 21 pymalloc and with ASAN, so we dump one in
21 22 $OUT/sanpy/lib/python2.7. This helps us wire that up. */
22 23 std::string selfpath(cselfpath);
23 24 std::string pypath;
24 25 auto pos = selfpath.rfind("/");
25 26 if (pos == std::string::npos) {
26 27 char wd[8192];
27 getcwd(wd, 8192);
28 if (!getcwd(wd, 8192)) {
29 std::cerr << "Failed to call getcwd: errno " << errno
30 << std::endl;
31 exit(1);
32 }
28 33 pypath = std::string(wd) + subdir;
29 34 } else {
30 35 pypath = selfpath.substr(0, pos) + subdir;
31 36 }
32 37 strncpy(cpypath, pypath.c_str(), pypath.size());
33 38 setenv("PYTHONPATH", cpypath, 1);
34 39 setenv("PYTHONNOUSERSITE", "1", 1);
35 40 /* prevent Python from looking up users in the fuzz environment */
36 41 setenv("PYTHONUSERBASE", cpypath, 1);
37 42 Py_SetPythonHome(cpypath);
38 43 Py_InitializeEx(0);
39 44 mainmod = PyImport_AddModule("__main__");
40 45 globals = PyModule_GetDict(mainmod);
41 46 initparsers();
42 47 }
43 48
44 49 PyObject *pyglobals()
45 50 {
46 51 return globals;
47 52 }
48 53
49 54 } // namespace contrib
General Comments 0
You need to be logged in to leave comments. Login now