Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f60bf0e1
Commit
f60bf0e1
authored
Jul 09, 2018
by
Serhiy Storchaka
Committed by
GitHub
Jul 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-22689: Copy the result of getenv() in sys_breakpointhook(). (GH-8194)
parent
b796e7dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletion
+14
-1
Python/sysmodule.c
Python/sysmodule.c
+14
-1
No files found.
Python/sysmodule.c
View file @
f60bf0e1
...
...
@@ -107,7 +107,7 @@ static PyObject *
sys_breakpointhook
(
PyObject
*
self
,
PyObject
*
const
*
args
,
Py_ssize_t
nargs
,
PyObject
*
keywords
)
{
assert
(
!
PyErr_Occurred
());
c
onst
c
har
*
envar
=
Py_GETENV
(
"PYTHONBREAKPOINT"
);
char
*
envar
=
Py_GETENV
(
"PYTHONBREAKPOINT"
);
if
(
envar
==
NULL
||
strlen
(
envar
)
==
0
)
{
envar
=
"pdb.set_trace"
;
...
...
@@ -116,6 +116,15 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
/* The breakpoint is explicitly no-op'd. */
Py_RETURN_NONE
;
}
/* According to POSIX the string returned by getenv() might be invalidated
* or the string content might be overwritten by a subsequent call to
* getenv(). Since importing a module can performs the getenv() calls,
* we need to save a copy of envar. */
envar
=
_PyMem_RawStrdup
(
envar
);
if
(
envar
==
NULL
)
{
PyErr_NoMemory
();
return
NULL
;
}
const
char
*
last_dot
=
strrchr
(
envar
,
'.'
);
const
char
*
attrname
=
NULL
;
PyObject
*
modulepath
=
NULL
;
...
...
@@ -131,12 +140,14 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
attrname
=
last_dot
+
1
;
}
if
(
modulepath
==
NULL
)
{
PyMem_RawFree
(
envar
);
return
NULL
;
}
PyObject
*
fromlist
=
Py_BuildValue
(
"(s)"
,
attrname
);
if
(
fromlist
==
NULL
)
{
Py_DECREF
(
modulepath
);
PyMem_RawFree
(
envar
);
return
NULL
;
}
PyObject
*
module
=
PyImport_ImportModuleLevelObject
(
...
...
@@ -154,6 +165,7 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
if
(
hook
==
NULL
)
{
goto
error
;
}
PyMem_RawFree
(
envar
);
PyObject
*
retval
=
_PyObject_FastCallKeywords
(
hook
,
args
,
nargs
,
keywords
);
Py_DECREF
(
hook
);
return
retval
;
...
...
@@ -164,6 +176,7 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
int
status
=
PyErr_WarnFormat
(
PyExc_RuntimeWarning
,
0
,
"Ignoring unimportable $PYTHONBREAKPOINT:
\"
%s
\"
"
,
envar
);
PyMem_RawFree
(
envar
);
if
(
status
<
0
)
{
/* Printing the warning raised an exception. */
return
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment