mirror of
https://github.com/daeuniverse/dae.git
synced 2024-12-22 21:14:59 +07:00
fix(config_parser): potential panic due to out of index (#108)
This commit is contained in:
parent
035332a89d
commit
cbcbec9a1a
@ -86,10 +86,18 @@ func (w *Walker) parseFunctionPrototype(ctx *dae_config.FunctionPrototypeContext
|
||||
children := ctx.GetChildren()
|
||||
not := false
|
||||
offset := 0
|
||||
if len(children) == 0 {
|
||||
w.ReportError(ctx, ErrorType_Unsupported, "bad function prototype expression")
|
||||
return nil
|
||||
}
|
||||
if children[0].(*antlr.TerminalNodeImpl).GetText() == "!" {
|
||||
offset++
|
||||
not = true
|
||||
}
|
||||
if len(children) <= offset+2 {
|
||||
w.ReportError(ctx, ErrorType_Unsupported, "bad function prototype expression")
|
||||
return nil
|
||||
}
|
||||
funcName := children[offset+0].(*antlr.TerminalNodeImpl).GetText()
|
||||
paramList := children[offset+2].(*dae_config.OptParameterListContext)
|
||||
children = paramList.GetChildren()
|
||||
@ -151,6 +159,10 @@ func (p *literalExpressionParser) Parse(ctx *dae_config.LiteralExpressionContext
|
||||
|
||||
func (w *Walker) parseDeclaration(ctx dae_config.IDeclarationContext) *Param {
|
||||
children := ctx.GetChildren()
|
||||
if len(children) < 3 {
|
||||
w.ReportError(ctx, ErrorType_Unsupported, "bad declaration expression")
|
||||
return nil
|
||||
}
|
||||
key := children[0].(*antlr.TerminalNodeImpl).GetText()
|
||||
switch valueCtx := children[2].(type) {
|
||||
case *dae_config.LiteralExpressionContext:
|
||||
@ -202,6 +214,10 @@ func (w *Walker) parseFunctionPrototypeExpression(ctx dae_config.IFunctionProtot
|
||||
|
||||
func (w *Walker) parseRoutingRule(ctx dae_config.IRoutingRuleContext) *RoutingRule {
|
||||
children := ctx.GetChildren()
|
||||
if len(children) < 3 {
|
||||
w.ReportError(ctx, ErrorType_Unsupported, "bad routing rule expression")
|
||||
return nil
|
||||
}
|
||||
//logrus.Debugln(ctx.GetText(), children)
|
||||
functionList, ok := children[0].(*dae_config.FunctionPrototypeExpressionContext)
|
||||
if !ok {
|
||||
|
Loading…
Reference in New Issue
Block a user