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
ffb0a804
Commit
ffb0a804
authored
Mar 06, 2007
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #1638879: don't accept strings with embedded NUL bytes in long().
(backport from rev. 54173)
parent
8c9b3d6a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
Lib/test/test_builtin.py
Lib/test/test_builtin.py
+5
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/longobject.c
Objects/longobject.c
+18
-1
No files found.
Lib/test/test_builtin.py
View file @
ffb0a804
...
@@ -1017,6 +1017,11 @@ class BuiltinTest(unittest.TestCase):
...
@@ -1017,6 +1017,11 @@ class BuiltinTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
long
,
'53'
,
40
)
self
.
assertRaises
(
ValueError
,
long
,
'53'
,
40
)
self
.
assertRaises
(
TypeError
,
long
,
1
,
12
)
self
.
assertRaises
(
TypeError
,
long
,
1
,
12
)
# SF patch #1638879: embedded NULs were not detected with
# explicit base
self
.
assertRaises
(
ValueError
,
long
,
'123
\
0
'
,
10
)
self
.
assertRaises
(
ValueError
,
long
,
'123
\
x00
245'
,
20
)
self
.
assertEqual
(
long
(
'100000000000000000000000000000000'
,
2
),
self
.
assertEqual
(
long
(
'100000000000000000000000000000000'
,
2
),
4294967296
)
4294967296
)
self
.
assertEqual
(
long
(
'102002022201221111211'
,
3
),
4294967296
)
self
.
assertEqual
(
long
(
'102002022201221111211'
,
3
),
4294967296
)
...
...
Misc/NEWS
View file @
ffb0a804
...
@@ -12,6 +12,8 @@ What's New in Python 2.5.1c1?
...
@@ -12,6 +12,8 @@ What's New in Python 2.5.1c1?
Core and builtins
Core and builtins
-----------------
-----------------
- Patch #1638879: don'
t
accept
strings
with
embedded
NUL
bytes
in
long
().
-
Bug
#
1674503
:
close
the
file
opened
by
execfile
()
in
an
error
condition
.
-
Bug
#
1674503
:
close
the
file
opened
by
execfile
()
in
an
error
condition
.
-
Patch
#
1674228
:
when
assigning
a
slice
(
old
-
style
),
check
for
the
-
Patch
#
1674228
:
when
assigning
a
slice
(
old
-
style
),
check
for
the
...
...
Objects/longobject.c
View file @
ffb0a804
...
@@ -3287,8 +3287,25 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3287,8 +3287,25 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
PyLong_FromLong
(
0L
);
return
PyLong_FromLong
(
0L
);
if
(
base
==
-
909
)
if
(
base
==
-
909
)
return
PyNumber_Long
(
x
);
return
PyNumber_Long
(
x
);
else
if
(
PyString_Check
(
x
))
else
if
(
PyString_Check
(
x
))
{
/* Since PyLong_FromString doesn't have a length parameter,
* check here for possible NULs in the string. */
char
*
string
=
PyString_AS_STRING
(
x
);
if
(
strlen
(
string
)
!=
PyString_Size
(
x
))
{
/* create a repr() of the input string,
* just like PyLong_FromString does. */
PyObject
*
srepr
;
srepr
=
PyObject_Repr
(
x
);
if
(
srepr
==
NULL
)
return
NULL
;
PyErr_Format
(
PyExc_ValueError
,
"invalid literal for long() with base %d: %s"
,
base
,
PyString_AS_STRING
(
srepr
));
Py_DECREF
(
srepr
);
return
NULL
;
}
return
PyLong_FromString
(
PyString_AS_STRING
(
x
),
NULL
,
base
);
return
PyLong_FromString
(
PyString_AS_STRING
(
x
),
NULL
,
base
);
}
#ifdef Py_USING_UNICODE
#ifdef Py_USING_UNICODE
else
if
(
PyUnicode_Check
(
x
))
else
if
(
PyUnicode_Check
(
x
))
return
PyLong_FromUnicode
(
PyUnicode_AS_UNICODE
(
x
),
return
PyLong_FromUnicode
(
PyUnicode_AS_UNICODE
(
x
),
...
...
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