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
e5dc9924
Commit
e5dc9924
authored
May 17, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When upgrading objects in builder, make sure to zero out the old location.
parent
35adf54b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
encoding-test.c++
c++/src/capnproto/encoding-test.c++
+0
-0
layout.c++
c++/src/capnproto/layout.c++
+19
-5
No files found.
c++/src/capnproto/encoding-test.c++
View file @
e5dc9924
This diff is collapsed.
Click to expand it.
c++/src/capnproto/layout.c++
View file @
e5dc9924
...
...
@@ -476,10 +476,9 @@ struct WireHelpers {
static
CAPNPROTO_ALWAYS_INLINE
(
StructBuilder
getWritableStructPointer
(
WirePointer
*
ref
,
SegmentBuilder
*
segment
,
StructSize
size
,
const
word
*
defaultValue
))
{
word
*
ptr
;
if
(
ref
->
isNull
())
{
useDefault
:
word
*
ptr
;
if
(
defaultValue
==
nullptr
||
reinterpret_cast
<
const
WirePointer
*>
(
defaultValue
)
->
isNull
())
{
ptr
=
allocate
(
ref
,
segment
,
size
.
total
(),
WirePointer
::
STRUCT
);
...
...
@@ -514,7 +513,7 @@ struct WireHelpers {
std
::
max
<
WirePointerCount
>
(
oldPointerCount
,
size
.
pointers
);
WordCount
totalSize
=
newDataSize
+
newPointerCount
*
WORDS_PER_POINTER
;
ptr
=
allocate
(
ref
,
segment
,
totalSize
,
WirePointer
::
STRUCT
);
word
*
ptr
=
allocate
(
ref
,
segment
,
totalSize
,
WirePointer
::
STRUCT
);
ref
->
structRef
.
set
(
newDataSize
,
newPointerCount
);
// Copy data section.
...
...
@@ -526,6 +525,14 @@ struct WireHelpers {
transferPointer
(
segment
,
newPointerSection
+
i
,
oldSegment
,
oldPointerSection
+
i
);
}
// Zero out old location. This has two purposes:
// 1) We don't want to leak the original contents of the struct when the message is written
// out as it may contain secrets that the caller intends to remove from the new copy.
// 2) Zeros will be deflated by packing, making this dead memory almost-free if it ever
// hits the wire.
memset
(
oldPtr
,
0
,
(
oldDataSize
+
oldPointerCount
*
WORDS_PER_POINTER
)
*
BYTES_PER_WORD
/
BYTES
);
return
StructBuilder
(
segment
,
ptr
,
newPointerSection
,
newDataSize
*
BITS_PER_WORD
,
newPointerCount
,
0
*
BITS
);
}
else
{
...
...
@@ -597,7 +604,6 @@ struct WireHelpers {
useDefault
:
if
(
defaultValue
==
nullptr
||
reinterpret_cast
<
const
WirePointer
*>
(
defaultValue
)
->
isNull
())
{
memset
(
origRef
,
0
,
sizeof
(
*
origRef
));
return
ListBuilder
();
}
word
*
ptr
=
copyMessage
(
origSegment
,
origRef
,
...
...
@@ -697,7 +703,6 @@ struct WireHelpers {
useDefault
:
if
(
defaultValue
==
nullptr
||
reinterpret_cast
<
const
WirePointer
*>
(
defaultValue
)
->
isNull
())
{
memset
(
origRef
,
0
,
sizeof
(
*
origRef
));
return
ListBuilder
();
}
word
*
ptr
=
copyMessage
(
origSegment
,
origRef
,
...
...
@@ -791,6 +796,9 @@ struct WireHelpers {
src
+=
oldStep
*
(
1
*
ELEMENTS
);
}
// Zero out old location. See explanation in getWritableStructPointer().
memset
(
oldPtr
,
0
,
oldStep
*
elementCount
*
BYTES_PER_WORD
/
BYTES
);
return
ListBuilder
(
origSegment
,
newPtr
,
newStep
*
BITS_PER_WORD
,
elementCount
,
newDataSize
*
BITS_PER_WORD
,
newPointerCount
);
}
else
if
(
oldSize
==
elementSize
.
preferredListEncoding
)
{
...
...
@@ -899,6 +907,9 @@ struct WireHelpers {
}
}
// Zero out old location. See explanation in getWritableStructPointer().
memset
(
oldPtr
,
0
,
roundUpToBytes
(
oldStep
*
elementCount
)
/
BYTES
);
return
ListBuilder
(
origSegment
,
newPtr
,
newStep
*
BITS_PER_WORD
,
elementCount
,
newDataSize
*
BITS_PER_WORD
,
newPointerCount
);
...
...
@@ -941,6 +952,9 @@ struct WireHelpers {
}
}
// Zero out old location. See explanation in getWritableStructPointer().
memset
(
oldPtr
,
0
,
roundUpToBytes
(
oldStep
*
elementCount
)
/
BYTES
);
return
ListBuilder
(
origSegment
,
newPtr
,
newDataSize
/
ELEMENTS
,
elementCount
,
newDataSize
,
0
*
POINTERS
);
}
...
...
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