Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
26af52ab
Commit
26af52ab
authored
Aug 14, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix memory corruption bug caused by an overrun when zeroing empty struct lists.
parent
b8d76f57
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
147 additions
and
1 deletion
+147
-1
layout.c++
c++/src/capnp/layout.c++
+2
-1
orphan-test.c++
c++/src/capnp/orphan-test.c++
+145
-0
No files found.
c++/src/capnp/layout.c++
View file @
26af52ab
...
...
@@ -444,6 +444,7 @@ struct WireHelpers {
for
(
uint
i
=
0
;
i
<
count
;
i
++
)
{
zeroObject
(
segment
,
reinterpret_cast
<
WirePointer
*>
(
ptr
)
+
i
);
}
memset
(
ptr
,
0
,
POINTER_SIZE_IN_WORDS
*
count
*
BYTES_PER_WORD
/
BYTES
);
break
;
}
case
FieldSize
:
:
INLINE_COMPOSITE
:
{
...
...
@@ -465,7 +466,7 @@ struct WireHelpers {
}
}
memset
(
ptr
,
0
,
(
elementTag
->
structRef
.
wordSize
()
+
POINTER_SIZE_IN_WORDS
)
memset
(
ptr
,
0
,
(
elementTag
->
structRef
.
wordSize
()
*
count
+
POINTER_SIZE_IN_WORDS
)
*
BYTES_PER_WORD
/
BYTES
);
break
;
}
...
...
c++/src/capnp/orphan-test.c++
View file @
26af52ab
...
...
@@ -474,6 +474,151 @@ TEST(Orphans, OrphanageFromBuilder) {
}
}
static
bool
allZero
(
const
word
*
begin
,
const
word
*
end
)
{
for
(
const
byte
*
pos
=
reinterpret_cast
<
const
byte
*>
(
begin
);
pos
<
reinterpret_cast
<
const
byte
*>
(
end
);
++
pos
)
{
if
(
*
pos
!=
0
)
return
false
;
}
return
true
;
}
TEST
(
Orphans
,
StructsZerodAfterUse
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
TestAllTypes
>
();
const
word
*
zerosStart
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
initTestMessage
(
root
.
initStructField
());
const
word
*
zerosEnd
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setTextField
(
"foo"
);
// guard against overruns
EXPECT_EQ
(
1u
,
builder
.
getSegmentsForOutput
().
size
());
// otherwise test is invalid
root
.
disownStructField
();
EXPECT_TRUE
(
allZero
(
zerosStart
,
zerosEnd
));
EXPECT_EQ
(
"foo"
,
root
.
getTextField
());
}
TEST
(
Orphans
,
ListsZerodAfterUse
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
TestAllTypes
>
();
const
word
*
zerosStart
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setUInt32List
({
12
,
34
,
56
});
const
word
*
zerosEnd
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setTextField
(
"foo"
);
// guard against overruns
EXPECT_EQ
(
1u
,
builder
.
getSegmentsForOutput
().
size
());
// otherwise test is invalid
root
.
disownUInt32List
();
EXPECT_TRUE
(
allZero
(
zerosStart
,
zerosEnd
));
EXPECT_EQ
(
"foo"
,
root
.
getTextField
());
}
TEST
(
Orphans
,
EmptyListsZerodAfterUse
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
TestAllTypes
>
();
const
word
*
zerosStart
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
initUInt32List
(
0
);
const
word
*
zerosEnd
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setTextField
(
"foo"
);
// guard against overruns
EXPECT_EQ
(
1u
,
builder
.
getSegmentsForOutput
().
size
());
// otherwise test is invalid
root
.
disownUInt32List
();
EXPECT_TRUE
(
allZero
(
zerosStart
,
zerosEnd
));
EXPECT_EQ
(
"foo"
,
root
.
getTextField
());
}
TEST
(
Orphans
,
StructListsZerodAfterUse
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
TestAllTypes
>
();
const
word
*
zerosStart
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
{
auto
list
=
root
.
initStructList
(
2
);
initTestMessage
(
list
[
0
]);
initTestMessage
(
list
[
1
]);
}
const
word
*
zerosEnd
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setTextField
(
"foo"
);
// guard against overruns
EXPECT_EQ
(
1u
,
builder
.
getSegmentsForOutput
().
size
());
// otherwise test is invalid
root
.
disownStructList
();
EXPECT_TRUE
(
allZero
(
zerosStart
,
zerosEnd
));
EXPECT_EQ
(
"foo"
,
root
.
getTextField
());
}
TEST
(
Orphans
,
EmptyStructListsZerodAfterUse
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
TestAllTypes
>
();
const
word
*
zerosStart
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
initStructList
(
0
);
const
word
*
zerosEnd
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setTextField
(
"foo"
);
// guard against overruns
EXPECT_EQ
(
1u
,
builder
.
getSegmentsForOutput
().
size
());
// otherwise test is invalid
root
.
disownStructList
();
EXPECT_TRUE
(
allZero
(
zerosStart
,
zerosEnd
));
EXPECT_EQ
(
"foo"
,
root
.
getTextField
());
}
TEST
(
Orphans
,
TextZerodAfterUse
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
TestAllTypes
>
();
const
word
*
zerosStart
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setTextField
(
"abcd123"
);
const
word
*
zerosEnd
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setDataField
(
data
(
"foo"
));
// guard against overruns
EXPECT_EQ
(
1u
,
builder
.
getSegmentsForOutput
().
size
());
// otherwise test is invalid
root
.
disownTextField
();
EXPECT_TRUE
(
allZero
(
zerosStart
,
zerosEnd
));
EXPECT_EQ
(
data
(
"foo"
),
root
.
getDataField
());
}
TEST
(
Orphans
,
DataZerodAfterUse
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
TestAllTypes
>
();
const
word
*
zerosStart
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setDataField
(
data
(
"abcd123"
));
const
word
*
zerosEnd
=
builder
.
getSegmentsForOutput
()[
0
].
end
();
root
.
setTextField
(
"foo"
);
// guard against overruns
EXPECT_EQ
(
1u
,
builder
.
getSegmentsForOutput
().
size
());
// otherwise test is invalid
root
.
disownDataField
();
EXPECT_TRUE
(
allZero
(
zerosStart
,
zerosEnd
));
EXPECT_EQ
(
"foo"
,
root
.
getTextField
());
}
}
// namespace
}
// namespace _ (private)
}
// namespace capnp
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