瀏覽代碼

Check length of timestring before taking slice

Taylor Gerring 10 年之前
父節點
當前提交
61bf29be36
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      logger/types.go

+ 6 - 1
logger/types.go

@@ -8,7 +8,12 @@ import (
 type utctime8601 struct{}
 
 func (utctime8601) MarshalJSON() ([]byte, error) {
-	return []byte(`"` + time.Now().UTC().Format(time.RFC3339Nano)[:26] + `Z"`), nil
+	timestr := time.Now().UTC().Format(time.RFC3339Nano)
+	// Bounds check
+	if len(timestr) > 26 {
+		timestr = timestr[:26]
+	}
+	return []byte(`"` + timestr + `Z"`), nil
 }
 
 type JsonLog interface {