Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bytes-sgx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Markus Becker
bytes-sgx
Commits
f693e038
Commit
f693e038
authored
8 years ago
by
Stefan Bühler
Committed by
Carl Lerche
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix buffer overflow in Sink for Vec<u8>
Fixes #46
parent
d0d27bd5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/buf/mod.rs
+3
-2
3 additions, 2 deletions
src/buf/mod.rs
test/test_buf.rs
+13
-0
13 additions, 0 deletions
test/test_buf.rs
with
16 additions
and
2 deletions
src/buf/mod.rs
+
3
−
2
View file @
f693e038
...
...
@@ -407,12 +407,13 @@ impl<'a> Sink for &'a mut Vec<u8> {
self
.clear
();
let
rem
=
buf
.remaining
();
let
cap
=
self
.capacity
();
// Ensure that the vec is big enough
if
rem
>
self
.capacity
()
{
self
.reserve
(
rem
-
cap
);
// current length is 0, so reserve completely
self
.reserve
(
rem
);
}
debug_assert!
(
rem
<=
self
.capacity
());
unsafe
{
{
...
...
This diff is collapsed.
Click to expand it.
test/test_buf.rs
+
13
−
0
View file @
f693e038
use
bytes
::{
Buf
};
use
byteorder
;
use
std
::
io
::{
Cursor
};
use
std
::
vec
::{
Vec
};
#[test]
pub
fn
test_fresh_cursor_vec
()
{
...
...
@@ -44,3 +45,15 @@ fn test_read_u16_buffer_underflow() {
let
mut
buf
=
Cursor
::
new
(
b"
\x21
"
);
buf
.read_u16
::
<
byteorder
::
BigEndian
>
();
}
#[test]
fn
test_vec_sink_capacity
()
{
use
bytes
::
Sink
;
let
mut
sink
:
Vec
<
u8
>
=
Vec
::
new
();
sink
.reserve
(
16
);
assert!
(
sink
.capacity
()
>=
16
,
"Capacity {} must be at least 16"
,
sink
.capacity
());
let
mut
source
=
Cursor
::
new
(
b"0123456789abcdef0123456789abcdef"
);
sink
.copy_from
(
&
mut
source
);
assert!
(
sink
.len
()
<=
sink
.capacity
(),
"Length {} must be less than or equal to capacity {}"
,
sink
.len
(),
sink
.capacity
());
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment