@@ -193,6 +193,10 @@ func (p *Parser) parseVersion() (int, error) {
193193func (p * Parser ) parseTimestamp () (time.Time , error ) {
194194 var ts time.Time
195195
196+ if p .cursor >= p .l {
197+ return ts , ErrInvalidTimeFormat
198+ }
199+
196200 if p .buff [p .cursor ] == NILVALUE {
197201 p .cursor ++
198202 return ts , nil
@@ -203,7 +207,7 @@ func (p *Parser) parseTimestamp() (time.Time, error) {
203207 return ts , err
204208 }
205209
206- if p .buff [p .cursor ] != 'T' {
210+ if p .cursor >= p . l || p . buff [p .cursor ] != 'T' {
207211 return ts , ErrInvalidTimeFormat
208212 }
209213
@@ -272,7 +276,7 @@ func parseFullDate(buff []byte, cursor *int, l int) (fullDate, error) {
272276 return fd , err
273277 }
274278
275- if buff [* cursor ] != '-' {
279+ if * cursor >= l || buff [* cursor ] != '-' {
276280 return fd , syslogparser .ErrTimestampUnknownFormat
277281 }
278282
@@ -283,7 +287,7 @@ func parseFullDate(buff []byte, cursor *int, l int) (fullDate, error) {
283287 return fd , err
284288 }
285289
286- if buff [* cursor ] != '-' {
290+ if * cursor >= l || buff [* cursor ] != '-' {
287291 return fd , syslogparser .ErrTimestampUnknownFormat
288292 }
289293
@@ -371,7 +375,7 @@ func parsePartialTime(buff []byte, cursor *int, l int) (partialTime, error) {
371375 return pt , err
372376 }
373377
374- if buff [* cursor ] != ':' {
378+ if * cursor >= l || buff [* cursor ] != ':' {
375379 return pt , ErrInvalidTimeFormat
376380 }
377381
@@ -392,7 +396,7 @@ func parsePartialTime(buff []byte, cursor *int, l int) (partialTime, error) {
392396
393397 // ----
394398
395- if buff [* cursor ] != '.' {
399+ if * cursor >= l || buff [* cursor ] != '.' {
396400 return pt , nil
397401 }
398402
@@ -458,7 +462,7 @@ func parseSecFrac(buff []byte, cursor *int, l int) (float64, error) {
458462// TIME-OFFSET = "Z" / TIME-NUMOFFSET
459463func parseTimeOffset (buff []byte , cursor * int , l int ) (* time.Location , error ) {
460464
461- if buff [* cursor ] == 'Z' {
465+ if * cursor >= l || buff [* cursor ] == 'Z' {
462466 * cursor ++
463467 return time .UTC , nil
464468 }
@@ -498,7 +502,7 @@ func getHourMinute(buff []byte, cursor *int, l int) (int, int, error) {
498502 return 0 , 0 , err
499503 }
500504
501- if buff [* cursor ] != ':' {
505+ if * cursor >= l || buff [* cursor ] != ':' {
502506 return 0 , 0 , ErrInvalidTimeFormat
503507 }
504508
@@ -588,8 +592,8 @@ func parseUpToLen(buff []byte, cursor *int, l int, maxLen int, e error) (string,
588592
589593 if found {
590594 result = string (buff [* cursor :to ])
591- } else if ( to > max ) {
592- to = max ; // don't go past max
595+ } else if to > max {
596+ to = max // don't go past max
593597 }
594598
595599 * cursor = to
0 commit comments