Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
system_security
Commits
29c54e37
Commit
29c54e37
authored
9 years ago
by
Chih-hung Hsieh
Committed by
Gerrit Code Review
9 years ago
Browse files
Options
Download
Plain Diff
Merge "Fix various memory errors."
parents
ec431738
eb1adaf5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
+26
-10
keystore/IKeystoreService.cpp
keystore/IKeystoreService.cpp
+24
-10
keystore/include/keystore/IKeystoreService.h
keystore/include/keystore/IKeystoreService.h
+2
-0
No files found.
keystore/IKeystoreService.cpp
View file @
29c54e37
...
...
@@ -221,31 +221,44 @@ static bool readKeymasterBlob(const Parcel& in, keymaster_blob_t* blob) {
return
false
;
}
blob
->
data_length
=
0
;
ssize_t
length
=
in
.
readInt32
();
if
(
length
<=
0
)
{
blob
->
data
=
nullptr
;
return
false
;
}
blob
->
data
=
reinterpret_cast
<
const
uint8_t
*>
(
in
.
readInplace
(
length
));
if
(
blob
->
data
)
{
blob
->
data_length
=
static_cast
<
size_t
>
(
length
);
}
blob
->
data
=
reinterpret_cast
<
const
uint8_t
*>
(
malloc
(
length
));
if
(
!
blob
->
data
)
return
false
;
const
void
*
buf
=
in
.
readInplace
(
length
);
if
(
!
buf
)
return
false
;
blob
->
data_length
=
static_cast
<
size_t
>
(
length
);
memcpy
(
const_cast
<
uint8_t
*>
(
blob
->
data
),
buf
,
length
);
return
true
;
}
void
KeymasterCertificateChain
::
readFromParcel
(
const
Parcel
&
in
)
{
keymaster_free_cert_chain
(
&
chain
);
ssize_t
count
=
in
.
readInt32
();
size_t
ucount
=
count
;
if
(
count
<
0
)
{
ucount
=
0
;
if
(
count
<
=
0
)
{
return
;
}
keymaster_free_cert_chain
(
&
chain
);
chain
.
entries
=
new
keymaster_blob_t
[
ucount
];
chain
.
entries
=
reinterpret_cast
<
keymaster_blob_t
*>
(
malloc
(
sizeof
(
keymaster_blob_t
)
*
ucount
));
if
(
!
chain
.
entries
)
{
ALOGE
(
"Error allocating memory for certificate chain"
);
return
;
}
memset
(
chain
.
entries
,
0
,
sizeof
(
keymaster_blob_t
)
*
ucount
);
for
(
size_t
i
=
0
;
i
<
ucount
;
++
i
)
{
if
(
!
readKeymasterBlob
(
in
,
&
chain
.
entries
[
i
]))
{
ALOGE
(
"Error reading certificate from parcel"
);
keymaster_free_cert_chain
(
&
chain
);
return
;
}
...
...
@@ -365,6 +378,7 @@ bool readKeymasterArgumentFromParcel(const Parcel& in, keymaster_key_param_t* ou
const
void
*
buf
=
in
.
readInplace
(
ulength
);
if
(
!
buf
||
!
data
)
{
ALOGE
(
"Failed to allocate buffer for keymaster blob param"
);
free
(
data
);
return
false
;
}
memcpy
(
data
,
buf
,
ulength
);
...
...
This diff is collapsed.
Click to expand it.
keystore/include/keystore/IKeystoreService.h
View file @
29c54e37
...
...
@@ -97,6 +97,8 @@ struct KeymasterCertificateChain {
void
readFromParcel
(
const
Parcel
&
in
);
void
writeToParcel
(
Parcel
*
out
)
const
;
void
FreeChain
();
keymaster_cert_chain_t
chain
;
};
...
...
This diff is collapsed.
Click to expand it.
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