Skip to content
Permalink
Browse files

fixed #698 crash of daemon on parse JSON

  • Loading branch information...
tomatolog committed Feb 18, 2019
1 parent c3ce2a7 commit e2f775437df922674d772ed4417780492502e65a
Showing with 18 additions and 7 deletions.
  1. +5 −0 src/sphinxjson.cpp
  2. +13 −7 src/sphinxjson.y
@@ -666,6 +666,11 @@ class JsonParser_c : public BsonHelper
}
return true;
}

void AddNode ( const JsonNode_t & tNode )
{
m_dNodes.Add ( tNode );
}
};

// unused parameter, simply to avoid type clash between all my yylex() functions
@@ -45,18 +45,20 @@ value:
key_value_list:
// empty
{
$$ = JsonNode_t();
$$.m_eType = JSON_OBJECT;
$$.m_dChildren.m_iStart = -1;
$$.m_dChildren.m_iLen = 0;
}
| key ':' value
{
$$ = JsonNode_t();
$$.m_eType = JSON_OBJECT;
$$.m_dChildren.m_iStart = $$.m_iNext = pParser->m_dNodes.GetLength();
$$.m_dChildren.m_iLen = 1;
$3.m_sName = $1.m_sValue;
pParser->m_dNodes.Add($3);
pParser->AddNode($3);
}
| key_value_list ',' key ':' value
@@ -66,28 +68,31 @@ key_value_list:
yyerror ( pParser, "unexpected ','" );
YYERROR;
}
$$ = JsonNode_t();
$$.m_eType = JSON_OBJECT;
$$.m_dChildren.m_iStart = $1.m_dChildren.m_iStart;
$$.m_dChildren.m_iLen = $1.m_dChildren.m_iLen+1;
$$.m_iNext = pParser->m_dNodes[$1.m_iNext].m_iNext = pParser->m_dNodes.GetLength();
$$.m_dChildren.m_iStart = $1.m_dChildren.m_iStart;
$$.m_dChildren.m_iLen = $1.m_dChildren.m_iLen+1;
$$.m_iNext = pParser->m_dNodes[$1.m_iNext].m_iNext = pParser->m_dNodes.GetLength();
$5.m_sName = $3.m_sValue;
pParser->m_dNodes.Add($5);
pParser->AddNode($5);
}
;
value_list:
// empty
{
$$ = JsonNode_t();
$$.m_eType = JSON_MIXED_VECTOR;
$$.m_dChildren.m_iStart = -1;
$$.m_dChildren.m_iLen = 0;
}
| value
{
$$ = JsonNode_t();
$$.m_eType = JSON_MIXED_VECTOR;
$$.m_dChildren.m_iStart = $$.m_iNext = pParser->m_dNodes.GetLength();
$$.m_dChildren.m_iLen = 1;
pParser->m_dNodes.Add($1);
pParser->AddNode($1);
}
| value_list ',' value
{
@@ -96,11 +101,12 @@ value_list:
yyerror ( pParser, "unexpected ','" );
YYERROR;
}
$$ = JsonNode_t();
$$.m_eType = JSON_MIXED_VECTOR;
$$.m_dChildren.m_iStart = $1.m_dChildren.m_iStart;
$$.m_dChildren.m_iLen = $1.m_dChildren.m_iLen+1;
$$.m_iNext = pParser->m_dNodes[$1.m_iNext].m_iNext = pParser->m_dNodes.GetLength();
pParser->m_dNodes.Add($3);
pParser->AddNode($3);
}
;

0 comments on commit e2f7754

Please sign in to comment.
You can’t perform that action at this time.