Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
32151f87
Commit
32151f87
authored
9 years ago
by
scoder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #444 from Nikratio/master
__Pyx_decode_c_string: check for overflow when calling strlen.
parents
6018c0db
cad0d9f8
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+11
-2
No files found.
Cython/Utility/StringTools.c
View file @
32151f87
...
...
@@ -395,14 +395,23 @@ static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
//@requires: IncludeStringH
/* duplicate code to avoid calling strlen() if start >= 0 and stop >= 0 */
/* Casting to Py_ssize_t and checking for negative values to determine
* if overflow occured should be safe in practice (it's undefined
* behavior by C99, but common behavior for systems with
* two-complement representation).
*/
static
CYTHON_INLINE
PyObject
*
__Pyx_decode_c_string
(
const
char
*
cstring
,
Py_ssize_t
start
,
Py_ssize_t
stop
,
const
char
*
encoding
,
const
char
*
errors
,
PyObject
*
(
*
decode_func
)(
const
char
*
s
,
Py_ssize_t
size
,
const
char
*
errors
))
{
Py_ssize_t
length
;
if
(
unlikely
((
start
<
0
)
|
(
stop
<
0
)))
{
length
=
strlen
(
cstring
);
length
=
(
Py_ssize_t
)
strlen
(
cstring
);
if
(
length
<
0
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"c-string too long to convert to Python"
);
return
NULL
;
}
if
(
start
<
0
)
{
start
+=
length
;
if
(
start
<
0
)
...
...
This diff is collapsed.
Click to expand it.
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