Go 1.15

最後更新


Go 1.15 發布於 2020-08-11,目前最新修補版為 go1.15.15,已停止支援,請升級到 go1.27.4。

版本介紹


Go 1.15 沒有語言變更,重點放在工具鏈品質:連結器(linker)大幅改寫,大型程式連結快約 20%、記憶體少約 30%,執行檔也平均小約 5%。另一個值得新手注意的是 go vet 開始警告 string(x)(x 為整數)的寫法,因為它產生的是字元,不是數字字串。

工具


  • GOPROXY 支援用 | 分隔代理伺服器,前一個發生任何錯誤時就改試下一個(, 則只在 404、410 時改試)。
  • 模組快取位置可用新的 GOMODCACHE 環境變數設定。
  • go vet 警告 string(x)(x 為 rune、byte 以外的整數型別),以及不可能成功的介面型別斷言。
  • 連結器採用新的目的檔格式並提高平行度;linux/amd64、linux/arm64 的 -buildmode=pie 預設改為內部連結,不再需要 C 連結器。
  • 編譯器會拒絕放錯位置的 //go: 指示(directive);新增 -spectre 旗標啟用 Spectre 緩解措施。
  • 這是最後一個支援只有 x87 浮點運算的 386 處理器的版本;macOS 需 10.12 以上,並移除 32 位元的 darwin 平台。

執行時與效能


  • 在多核心機器上配置小物件的效能更好,最差情況的延遲也更低。
  • 把小整數轉成介面值不再產生記憶體配置。
  • 對已關閉通道的非阻塞接收和開啟中的通道一樣快。
  • 以 bool、int、string 等基本型別為底層的自訂型別值傳給 panic 時,會印出實際的值而不是位址。

標準庫重點


  • 新增 time/tzdata,用 import _ "time/tzdata" 把時區資料庫嵌入程式,約增加 800KB。
  • X.509 憑證的 CommonName 不再被當成主機名稱使用(可暫時用 GODEBUG=x509ignoreCN=0 還原)。
  • testing 新增 T.TempDir、B.TempDir(測試結束自動刪除的暫存目錄)與 T.Deadline;TestMain 不必再呼叫 os.Exit。
  • os 檔案操作超過期限時回傳的錯誤可以用 errors.Is(err, os.ErrDeadlineExceeded) 判斷;os 與 net 會自動重試遇到 EINTR 的系統呼叫。
  • sync.Map 新增 LoadAndDelete;以 nil 作為父 context 呼叫 WithCancel 等函式會直接 panic。

string(x) 與數字轉字串


string(9786) 得到的是碼位 9786 對應的字元「☺」,不是字串 "9786"。要表達「轉成字元」請明確寫 string(rune(x));要轉成十進位字串則用 strconv.Itoa 或 fmt.Sprint。
  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. )
  6. func main() {
  7. n := 9786
  8. fmt.Println(string(rune(n)))
  9. fmt.Println(strconv.Itoa(n))
  10. fmt.Println(fmt.Sprint(n))
  11. }

  1. ☺
  2. 9786
  3. 9786

本版新增的棄用 API


以下 API 從 Go 1.15 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
套件符號官方說明
crypto/tlsConfig.SessionTicketKeyif this field is left at zero, session ticket keys will be automatically rotated every day and dropped after seven days. For customizing the rotation schedule or synchronizing servers that are terminating connections for the same host, use SetSessionTicketKeys.
crypto/tlsConnectionState.NegotiatedProtocolIsMutualthis value is always true.

修補版本


版本發布日期含安全修補內容(官方原文)
go1.15.12020-09-01是includes security fixes to the net/http/cgi and net/http/fcgi packages.
go1.15.22020-09-09否includes fixes to the compiler, runtime, documentation, the go command, and the net/mail, os, sync, and testing packages.
go1.15.32020-10-14否includes fixes to cgo, the compiler, runtime, the go command, and the bytes, plugin, and testing packages.
go1.15.42020-11-05否includes fixes to cgo, the compiler, linker, runtime, and the compress/flate, net/http, reflect, and time packages.
go1.15.52020-11-12是includes security fixes to the go command and the math/big package.
go1.15.62020-12-03否includes fixes to the compiler, linker, runtime, the go command, and the io package.
go1.15.72021-01-19是includes security fixes to the go command and the crypto/elliptic package.
go1.15.82021-02-04否includes fixes to the compiler, linker, runtime, the go command, and the net/http package.
go1.15.92021-03-10是includes security fixes to the encoding/xml package.
go1.15.102021-03-11否includes fixes to the compiler, the go command, and the net/http, os, syscall, and time packages.
go1.15.112021-04-01否includes fixes to cgo, the compiler, linker, runtime, the go command, and the database/sql and net/http packages.
go1.15.122021-05-06是includes a security fix to the net/http package, as well as bug fixes to the compiler, runtime, and the archive/zip, syscall, and time packages.
go1.15.132021-06-03是includes security fixes to the archive/zip, math/big, net, and net/http/httputil packages, as well as bug fixes to the linker, the go command, and the math/big and net/http packages.
go1.15.142021-07-12是includes a security fix to the crypto/tls package, as well as bug fixes to the linker and the net package.
go1.15.152021-08-05是includes a security fix to the net/http/httputil package, as well as bug fixes to the compiler, runtime, the go command, and the net/http package.

已知漏洞


在 Go 1.15 系列修補版中修正的漏洞共 14 個;仍影響最新修補版 go1.15.15 的漏洞共 176 個。

本系列已修正


編號CVE摘要(官方原文)修正於
GO-2022-0476CVE-2020-28367Arbitrary code execution via the go command with cgo in cmd/gogo1.14.12、go1.15.5
GO-2022-0475CVE-2020-28366Arbitrary code execution in go command with cgo in cmd/go and cmd/cgogo1.14.12、go1.15.5
GO-2022-0236CVE-2021-31525Panic due to large headers in net/http and golang.org/x/net/http/httpgutsgo1.15.12、go1.16.4
GO-2021-0245CVE-2021-36221Panic in ReverseProxy in net/http/httputilgo1.15.15、go1.16.7
GO-2021-0243CVE-2021-34558Panic on certain certificates in crypto/tlsgo1.15.14、go1.16.6
GO-2021-0242CVE-2021-33198Panic on inputs with large exponents in math/biggo1.15.13、go1.16.5
GO-2021-0241CVE-2021-33197Attacker can drop certain headers in net/http/httputilgo1.15.13、go1.16.5
GO-2021-0240CVE-2021-33196Panic when reading certain archives in archive/zipgo1.15.13、go1.16.5
GO-2021-0239CVE-2021-33195Improper sanitization when resolving values from DNS in netgo1.15.13、go1.16.5
GO-2021-0235CVE-2021-3114Incorrect operations on the P-224 curve in crypto/ellipticgo1.14.14、go1.15.7
GO-2021-0234CVE-2021-27918Infinite loop when decoding inputs in encoding/xmlgo1.15.9、go1.16.1
GO-2021-0226CVE-2020-24553Cross-site scripting in net/http/cgi and net/http/fcgigo1.14.8、go1.15.1
GO-2021-0069CVE-2020-28362Panic during division of very large numbers in math/biggo1.14.12、go1.15.5
GO-2021-0068CVE-2021-3115Arbitrary code injection via the go command with cgo on Windows in cmd/gogo1.14.14、go1.15.7

本版已停止支援,不會再修正這些漏洞;完整清單見 資安漏洞。

資料來源