Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions lib/univalue_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,41 +265,41 @@ bool UniValue::read(const char *raw, size_t size)

tok = getJsonToken(tokenVal, consumed, raw, end);
if (tok == JTOK_NONE || tok == JTOK_ERR)
return false;
goto return_fail;
raw += consumed;

bool isValueOpen = jsonTokenIsValue(tok) ||
tok == JTOK_OBJ_OPEN || tok == JTOK_ARR_OPEN;

if (expect(VALUE)) {
if (!isValueOpen)
return false;
goto return_fail;
clearExpect(VALUE);

} else if (expect(ARR_VALUE)) {
bool isArrValue = isValueOpen || (tok == JTOK_ARR_CLOSE);
if (!isArrValue)
return false;
goto return_fail;

clearExpect(ARR_VALUE);

} else if (expect(OBJ_NAME)) {
bool isObjName = (tok == JTOK_OBJ_CLOSE || tok == JTOK_STRING);
if (!isObjName)
return false;
goto return_fail;

} else if (expect(COLON)) {
if (tok != JTOK_COLON)
return false;
goto return_fail;
clearExpect(COLON);

} else if (!expect(COLON) && (tok == JTOK_COLON)) {
return false;
goto return_fail;
}

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

Expand Down Expand Up @@ -333,12 +333,12 @@ bool UniValue::read(const char *raw, size_t size)
case JTOK_OBJ_CLOSE:
case JTOK_ARR_CLOSE: {
if (!stack.size() || (last_tok == JTOK_COMMA))
return false;
goto return_fail;

VType utyp = (tok == JTOK_OBJ_CLOSE ? VOBJ : VARR);
UniValue *top = stack.back();
if (utyp != top->getType())
return false;
goto return_fail;

stack.pop_back();
clearExpect(OBJ_NAME);
Expand All @@ -348,11 +348,11 @@ bool UniValue::read(const char *raw, size_t size)

case JTOK_COLON: {
if (!stack.size())
return false;
goto return_fail;

UniValue *top = stack.back();
if (top->getType() != VOBJ)
return false;
goto return_fail;

setExpect(VALUE);
break;
Expand All @@ -361,7 +361,7 @@ bool UniValue::read(const char *raw, size_t size)
case JTOK_COMMA: {
if (!stack.size() ||
(last_tok == JTOK_COMMA) || (last_tok == JTOK_ARR_OPEN))
return false;
goto return_fail;

UniValue *top = stack.back();
if (top->getType() == VOBJ)
Expand Down Expand Up @@ -435,15 +435,19 @@ bool UniValue::read(const char *raw, size_t size)
}

default:
return false;
goto return_fail;
}
} while (!stack.empty ());

/* Check that nothing follows the initial construct (parsed above). */
tok = getJsonToken(tokenVal, consumed, raw, end);
if (tok != JTOK_NONE)
return false;
goto return_fail;

return true;

return_fail:
clear();
return false;
}