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。- package main
- import (
- "fmt"
- "strconv"
- )
- func main() {
- n := 9786
- fmt.Println(string(rune(n)))
- fmt.Println(strconv.Itoa(n))
- fmt.Println(fmt.Sprint(n))
- }
- ☺
- 9786
- 9786
本版新增的棄用 API
以下 API 從 Go 1.15 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
| 套件 | 符號 | 官方說明 |
|---|---|---|
crypto/tls | Config.SessionTicketKey | if 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/tls | ConnectionState.NegotiatedProtocolIsMutual | this value is always true. |
修補版本
| 版本 | 發布日期 | 含安全修補 | 內容(官方原文) |
|---|---|---|---|
go1.15.1 | 2020-09-01 | 是 | includes security fixes to the net/http/cgi and net/http/fcgi packages. |
go1.15.2 | 2020-09-09 | 否 | includes fixes to the compiler, runtime, documentation, the go command, and the net/mail, os, sync, and testing packages. |
go1.15.3 | 2020-10-14 | 否 | includes fixes to cgo, the compiler, runtime, the go command, and the bytes, plugin, and testing packages. |
go1.15.4 | 2020-11-05 | 否 | includes fixes to cgo, the compiler, linker, runtime, and the compress/flate, net/http, reflect, and time packages. |
go1.15.5 | 2020-11-12 | 是 | includes security fixes to the go command and the math/big package. |
go1.15.6 | 2020-12-03 | 否 | includes fixes to the compiler, linker, runtime, the go command, and the io package. |
go1.15.7 | 2021-01-19 | 是 | includes security fixes to the go command and the crypto/elliptic package. |
go1.15.8 | 2021-02-04 | 否 | includes fixes to the compiler, linker, runtime, the go command, and the net/http package. |
go1.15.9 | 2021-03-10 | 是 | includes security fixes to the encoding/xml package. |
go1.15.10 | 2021-03-11 | 否 | includes fixes to the compiler, the go command, and the net/http, os, syscall, and time packages. |
go1.15.11 | 2021-04-01 | 否 | includes fixes to cgo, the compiler, linker, runtime, the go command, and the database/sql and net/http packages. |
go1.15.12 | 2021-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.13 | 2021-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.14 | 2021-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.15 | 2021-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-0476 | CVE-2020-28367 | Arbitrary code execution via the go command with cgo in cmd/go | go1.14.12、go1.15.5 |
| GO-2022-0475 | CVE-2020-28366 | Arbitrary code execution in go command with cgo in cmd/go and cmd/cgo | go1.14.12、go1.15.5 |
| GO-2022-0236 | CVE-2021-31525 | Panic due to large headers in net/http and golang.org/x/net/http/httpguts | go1.15.12、go1.16.4 |
| GO-2021-0245 | CVE-2021-36221 | Panic in ReverseProxy in net/http/httputil | go1.15.15、go1.16.7 |
| GO-2021-0243 | CVE-2021-34558 | Panic on certain certificates in crypto/tls | go1.15.14、go1.16.6 |
| GO-2021-0242 | CVE-2021-33198 | Panic on inputs with large exponents in math/big | go1.15.13、go1.16.5 |
| GO-2021-0241 | CVE-2021-33197 | Attacker can drop certain headers in net/http/httputil | go1.15.13、go1.16.5 |
| GO-2021-0240 | CVE-2021-33196 | Panic when reading certain archives in archive/zip | go1.15.13、go1.16.5 |
| GO-2021-0239 | CVE-2021-33195 | Improper sanitization when resolving values from DNS in net | go1.15.13、go1.16.5 |
| GO-2021-0235 | CVE-2021-3114 | Incorrect operations on the P-224 curve in crypto/elliptic | go1.14.14、go1.15.7 |
| GO-2021-0234 | CVE-2021-27918 | Infinite loop when decoding inputs in encoding/xml | go1.15.9、go1.16.1 |
| GO-2021-0226 | CVE-2020-24553 | Cross-site scripting in net/http/cgi and net/http/fcgi | go1.14.8、go1.15.1 |
| GO-2021-0069 | CVE-2020-28362 | Panic during division of very large numbers in math/big | go1.14.12、go1.15.5 |
| GO-2021-0068 | CVE-2021-3115 | Arbitrary code injection via the go command with cgo on Windows in cmd/go | go1.14.14、go1.15.7 |
本版已停止支援,不會再修正這些漏洞;完整清單見 資安漏洞。