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
507ac3a5
Commit
507ac3a5
authored
Dec 13, 2013
by
Victor Stinner
Browse files
Options
Browse Files
Download
Plain Diff
(Merge 3.3) Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if
"%c" argument is not in range [0; 255].
parents
590cebe3
c9362cf8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
3 deletions
+25
-3
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+6
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/bytesobject.c
Objects/bytesobject.c
+16
-3
No files found.
Lib/test/test_bytes.py
View file @
507ac3a5
...
...
@@ -743,6 +743,12 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
self
.
assertEqual
(
PyBytes_FromFormat
(
b's:%s'
,
c_char_p
(
b'cstr'
)),
b's:cstr'
)
# Issue #19969
self
.
assertRaises
(
OverflowError
,
PyBytes_FromFormat
,
b'%c'
,
c_int
(
-
1
))
self
.
assertRaises
(
OverflowError
,
PyBytes_FromFormat
,
b'%c'
,
c_int
(
256
))
class
ByteArrayTest
(
BaseBytesTest
,
unittest
.
TestCase
):
type2test
=
bytearray
...
...
Misc/NEWS
View file @
507ac3a5
...
...
@@ -10,6 +10,9 @@ Release date: 2014-01-05
Core and Builtins
-----------------
- Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if "%c"
argument is not in range [0; 255].
- Issue #19787: PyThread_set_key_value() now always set the value. In Python
3.3, the function did nothing if the key already exists (if the current value
is a non-NULL pointer).
...
...
Objects/bytesobject.c
View file @
507ac3a5
...
...
@@ -195,8 +195,17 @@ PyBytes_FromFormatV(const char *format, va_list vargs)
switch
(
*
f
)
{
case
'c'
:
(
void
)
va_arg
(
count
,
int
);
/* fall through... */
{
int
c
=
va_arg
(
count
,
int
);
if
(
c
<
0
||
c
>
255
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"PyBytes_FromFormatV(): %c format "
"expects an integer in range [0; 255]"
);
return
NULL
;
}
n
++
;
break
;
}
case
'%'
:
n
++
;
break
;
...
...
@@ -276,8 +285,12 @@ PyBytes_FromFormatV(const char *format, va_list vargs)
switch
(
*
f
)
{
case
'c'
:
*
s
++
=
va_arg
(
vargs
,
int
);
{
int
c
=
va_arg
(
vargs
,
int
);
/* c has been checked for overflow in the first step */
*
s
++
=
(
unsigned
char
)
c
;
break
;
}
case
'd'
:
if
(
longflag
)
sprintf
(
s
,
"%ld"
,
va_arg
(
vargs
,
long
));
...
...
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