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
953807bc
Commit
953807bc
authored
Nov 09, 2015
by
Kamal Marhubi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check input is exhausted after parsing JSON
parent
f0990c9d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
json.c++
c++/src/capnp/compat/json.c++
+9
-2
No files found.
c++/src/capnp/compat/json.c++
View file @
953807bc
...
...
@@ -388,6 +388,8 @@ public:
void
parseValue
(
JsonValue
::
Builder
&
output
)
{
consumeWhitespace
();
KJ_DEFER
(
consumeWhitespace
());
KJ_REQUIRE
(
remaining_
.
size
()
>
0
,
"JSON message ends prematurely."
);
switch
(
nextChar
())
{
...
...
@@ -496,6 +498,10 @@ public:
consume
(
'}'
);
}
bool
inputExhausted
()
{
return
remaining_
.
size
()
==
0
||
remaining_
.
front
()
==
'\0'
;
}
char
nextChar
()
{
KJ_REQUIRE
(
remaining_
.
size
()
>
0
,
"JSON message ends prematurely."
);
return
remaining_
.
front
();
...
...
@@ -531,7 +537,7 @@ public:
template
<
typename
Predicate
>
kj
::
ArrayPtr
<
const
char
>
consumeWhile
(
Predicate
&&
predicate
)
{
auto
originalPos
=
remaining_
.
begin
();
while
(
predicate
(
nextChar
()))
{
advance
();
}
while
(
!
inputExhausted
()
&&
predicate
(
nextChar
()))
{
advance
();
}
return
kj
::
arrayPtr
(
originalPos
,
remaining_
.
begin
());
}
...
...
@@ -661,9 +667,10 @@ const kj::ArrayPtr<const char> Parser::TRUE = kj::ArrayPtr<const char>({'t','r',
void
JsonCodec
::
decodeRaw
(
kj
::
ArrayPtr
<
const
char
>
input
,
JsonValue
::
Builder
output
)
const
{
// TODO(security): should we check there are no non-whitespace characters left in input?
Parser
parser
(
impl
->
maxNestingDepth
,
input
);
parser
.
parseValue
(
output
);
KJ_REQUIRE
(
parser
.
inputExhausted
(),
"Input remains after parsing JSON."
);
}
// -----------------------------------------------------------------------------
...
...
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