From 0e3964d8c22ebc61feacef97ad1158f52e370a82 Mon Sep 17 00:00:00 2001 From: thbourlove Date: Thu, 14 Apr 2016 14:42:28 +0800 Subject: [PATCH] fix panic in transform iterator on division if left point is nil in division expr, the influxd server would panic. Now check left point before use it. --- CHANGELOG.md | 1 + influxql/select.go | 66 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b71c1144b..7f178ed1db5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ - [#6413](https://github.com/influxdata/influxdb/pull/6413): Prevent goroutine leak from persistent http connections. Thanks @aaronknister. - [#6414](https://github.com/influxdata/influxdb/pull/6414): Send "Connection: close" header for queries. - [#6425](https://github.com/influxdata/influxdb/pull/6425): Close idle tcp connections in HTTP client to prevent tcp conn leak. +- [#6419](https://github.com/influxdata/influxdb/issues/6419): Fix panic in transform iterator on division. @thbourlove ## v0.12.1 [2016-04-08] diff --git a/influxql/select.go b/influxql/select.go index 980b1f92dc1..03bacd9e52d 100644 --- a/influxql/select.go +++ b/influxql/select.go @@ -840,13 +840,33 @@ func buildTransformIterator(lhs Iterator, rhs Iterator, op Token, ic IteratorCre left: newBufIntegerIterator(left), right: newBufIntegerIterator(right), fn: func(a *IntegerPoint, b *IntegerPoint) *FloatPoint { + if a == nil && b == nil { + return nil + } else if a == nil { + return &FloatPoint{ + Name: b.Name, + Tags: b.Tags, + Time: b.Time, + Aux: b.Aux, + Nil: true, + } + } else if b == nil { + return &FloatPoint{ + Name: a.Name, + Tags: a.Tags, + Time: a.Time, + Aux: a.Aux, + Nil: true, + } + } + p := &FloatPoint{ Name: a.Name, Tags: a.Tags, Time: a.Time, Aux: a.Aux, } - if (a != nil && b != nil) && (!a.Nil && !b.Nil) { + if !a.Nil && !b.Nil { p.Value = fn(a.Value, b.Value) } else { p.Nil = true @@ -911,13 +931,33 @@ func buildTransformIterator(lhs Iterator, rhs Iterator, op Token, ic IteratorCre left: newBufFloatIterator(left), right: newBufFloatIterator(right), fn: func(a *FloatPoint, b *FloatPoint) *BooleanPoint { + if a == nil && b == nil { + return nil + } else if a == nil { + return &BooleanPoint{ + Name: b.Name, + Tags: b.Tags, + Time: b.Time, + Aux: b.Aux, + Nil: true, + } + } else if b == nil { + return &BooleanPoint{ + Name: a.Name, + Tags: a.Tags, + Time: a.Time, + Aux: a.Aux, + Nil: true, + } + } + p := &BooleanPoint{ Name: a.Name, Tags: a.Tags, Time: a.Time, Aux: a.Aux, } - if (a != nil && b != nil) && (!a.Nil && !b.Nil) { + if !a.Nil && !b.Nil { p.Value = fn(a.Value, b.Value) } else { p.Nil = true @@ -938,13 +978,33 @@ func buildTransformIterator(lhs Iterator, rhs Iterator, op Token, ic IteratorCre left: newBufIntegerIterator(left), right: newBufIntegerIterator(right), fn: func(a *IntegerPoint, b *IntegerPoint) *BooleanPoint { + if a == nil && b == nil { + return nil + } else if a == nil { + return &BooleanPoint{ + Name: b.Name, + Tags: b.Tags, + Time: b.Time, + Aux: b.Aux, + Nil: true, + } + } else if b == nil { + return &BooleanPoint{ + Name: a.Name, + Tags: a.Tags, + Time: a.Time, + Aux: a.Aux, + Nil: true, + } + } + p := &BooleanPoint{ Name: a.Name, Tags: a.Tags, Time: a.Time, Aux: a.Aux, } - if (a != nil && b != nil) && (!a.Nil && !b.Nil) { + if !a.Nil && !b.Nil { p.Value = fn(a.Value, b.Value) } else { p.Nil = true