Skip to content

Commit

Permalink
parser: Ensure multiple values cannot follow each other
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarzik committed Nov 7, 2015
1 parent eb6cd64 commit ccf3575
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ TEST_FILES = \
$(TEST_DATA_DIR)/fail34.json \
$(TEST_DATA_DIR)/fail35.json \
$(TEST_DATA_DIR)/fail36.json \
$(TEST_DATA_DIR)/fail37.json \
$(TEST_DATA_DIR)/fail3.json \
$(TEST_DATA_DIR)/fail4.json \
$(TEST_DATA_DIR)/fail5.json \
Expand Down
13 changes: 12 additions & 1 deletion lib/univalue_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
enum expect_bits {
EXP_OBJ_NAME = (1U << 0),
EXP_COLON = (1U << 1),
EXP_VALUE = (1U << 3),
EXP_ARR_VALUE = (1U << 2),
EXP_VALUE = (1U << 3),
EXP_NOT_VALUE = (1U << 4),
};

#define expect(bit) (expectMask & (EXP_##bit))
Expand Down Expand Up @@ -300,6 +301,12 @@ bool UniValue::read(const char *raw)
return false;
}

if (expect(NOT_VALUE)) {
if (isValueOpen)
return false;
clearExpect(NOT_VALUE);
}

switch (tok) {

case JTOK_OBJ_OPEN:
Expand Down Expand Up @@ -339,6 +346,7 @@ bool UniValue::read(const char *raw)

stack.pop_back();
clearExpect(OBJ_NAME);
setExpect(NOT_VALUE);
break;
}

Expand Down Expand Up @@ -390,6 +398,7 @@ bool UniValue::read(const char *raw)
UniValue *top = stack.back();
top->values.push_back(tmpVal);

setExpect(NOT_VALUE);
break;
}

Expand All @@ -401,6 +410,7 @@ bool UniValue::read(const char *raw)
UniValue *top = stack.back();
top->values.push_back(tmpVal);

setExpect(NOT_VALUE);
break;
}

Expand All @@ -419,6 +429,7 @@ bool UniValue::read(const char *raw)
top->values.push_back(tmpVal);
}

setExpect(NOT_VALUE);
break;
}

Expand Down
1 change: 1 addition & 0 deletions test/fail37.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a":1 "b":2}
3 changes: 2 additions & 1 deletion test/unitester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ static const char *filenames[] = {
"fail32.json",
"fail33.json",
"fail34.json",
// "fail35.json", // investigate - issue #15
"fail35.json",
"fail36.json",
"fail37.json",
"fail3.json",
"fail4.json", // extra comma
"fail5.json",
Expand Down

0 comments on commit ccf3575

Please sign in to comment.