Go 1.12

最後更新


Go 1.12 發布於 2019-02-25,目前最新修補版為 go1.12.17,已停止支援,請升級到 go1.27.4。

版本介紹


Go 1.12 是模組功能持續成熟的一版:go.mod 的 go 指令開始代表模組使用的語言版本,模組下載也能安全地平行執行。對寫程式最直接的改變是 fmt 印映射時會依鍵排序,輸出從此可重現,測試比對更方便;crypto/tls 也開始可選擇啟用 TLS 1.3。

工具


  • go.mod 中的 go 1.12 這類指令代表該模組使用的語言版本。
  • 設定 GO111MODULE=on 時,go get、go list 等命令在模組目錄之外也能執行。
  • 下載與解壓模組的 go 命令可以安全地同時執行;replace 指令會在查詢網路前優先使用。
  • go tool vet 不再支援,請改用 go vet。
  • 建置快取成為必要條件,無法再用 GOCACHE=off 關閉。
  • 這是最後一個支援二進位套件(binary-only package)的版本。

執行時與效能


  • 當堆積中大部分物件仍存活時,清掃效能大幅提升,降低垃圾回收後的配置延遲。
  • 執行時更積極地把記憶體還給作業系統;Linux 上改用 MADV_FREE。
  • 計時器與截止時間(deadline)的程式碼更快,並能隨 CPU 數擴展,網路連線設定 deadline 時特別有感。
  • 編譯器能內嵌更多函式,取得呼叫堆疊時務必使用 runtime.CallersFrames。

標準庫重點


  • fmt 印出映射時依鍵排序,數字、字串依大小排列。
  • crypto/tls 支援 TLS 1.3,此版需以 GODEBUG=tls13=1 啟用,Go 1.13 起預設開啟。
  • strings 與 bytes 新增 ReplaceAll,等同 Replace(s, old, new, -1)。
  • reflect 新增 Value.MapRange 與 MapIter,用迭代器走訪映射。
  • os 新增 UserHomeDir;strings.Builder 新增 Cap 方法。

fmt 依鍵排序印出映射


映射本身的走訪順序依然不固定,但 fmt 印出時會先把鍵排好。需要在自己的程式中依序處理映射時,仍要自行排序鍵。
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. func main() {
  7. scores := map[string]int{"carol": 70, "alice": 90, "bob": 80}
  8. fmt.Println(scores)
  9. flags := map[int]bool{3: true, 1: false, 2: true}
  10. fmt.Printf("%v\n", flags)
  11. fmt.Println(strings.ReplaceAll("a-b-c-d", "-", "/"))
  12. }

  1. map[alice:90 bob:80 carol:70]
  2. map[1:false 2:true 3:true]
  3. a/b/c/d

本版新增的棄用 API


以下 API 從 Go 1.12 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
套件符號官方說明
crypto/rc4Cipher.ResetReset can't guarantee that the key will be entirely removed from the process's memory.
crypto/x509CertificateRequest.AttributesUse Extensions and ExtraExtensions instead for parsing and generating the requestedExtensions attribute.
go/importerForUse [ForCompiler], which populates a FileSet with the positions of objects created by the importer.
netDialer.DualStackFast Fallback is enabled by default. To disable, set FallbackDelay to a negative value.
net/httpErrUnexpectedTrailerErrUnexpectedTrailer is no longer returned by anything in the net/http package. Callers should not compare errors against this variable.
regexpRegexp.CopyIn earlier releases, when using a [Regexp] in multiple goroutines, giving each goroutine its own copy helped to avoid lock contention. As of Go 1.12, using Copy is no longer necessary to avoid lock contention. Copy may still be appropriate if the reason for its use is to make two copies with different [Regexp.Longest] settings.

修補版本


版本發布日期含安全修補內容(官方原文)
go1.12.12019-03-14否includes fixes to cgo, the compiler, the go command, and the fmt, net/smtp, os, path/filepath, sync, and text/template packages.
go1.12.22019-04-05是includes security fixes to the runtime, as well as bug fixes to the compiler, the go command, and the doc, net, net/http/httputil, and os packages.
go1.12.32019-04-08否was accidentally released without its intended fix. It is identical to go1.12.2, except for its version number. The intended fix is in go1.12.4.
go1.12.42019-04-11否fixes an issue where using the prebuilt binary releases on older versions of GNU/Linux led to failures when linking programs that used cgo. Only Linux users who hit this issue need to update.
go1.12.52019-05-06否includes fixes to the compiler, the linker, the go command, the runtime, and the os package.
go1.12.62019-06-11否includes fixes to the compiler, the linker, the go command, and the crypto/x509, net/http, and os packages.
go1.12.72019-07-08否includes fixes to cgo, the compiler, and the linker.
go1.12.82019-08-13是includes security fixes to the net/http and net/url packages.
go1.12.92019-08-15否includes fixes to the linker, and the math/big and os packages.
go1.12.102019-09-25是includes security fixes to the net/http and net/textproto packages.
go1.12.112019-10-17是includes security fixes to the crypto/dsa package.
go1.12.122019-10-17否includes fixes to the go command, runtime, and the net and syscall packages.
go1.12.132019-10-31否fixes an issue on macOS 10.15 Catalina where the non-notarized installer and binaries were being rejected by Gatekeeper. Only macOS users who hit this issue need to update.
go1.12.142019-12-04否includes a fix to the runtime.
go1.12.152020-01-09否includes fixes to the runtime and the net/http package.
go1.12.162020-01-28是includes two security fixes to the crypto/x509 package.
go1.12.172020-02-12否includes a fix to the runtime.

已知漏洞


在 Go 1.12 系列修補版中修正的漏洞共 7 個;仍影響最新修補版 go1.12.17 的漏洞共 192 個。

本系列已修正


編號CVE摘要(官方原文)修正於
GO-2022-0536CVE-2019-9512Reset flood in net/http and golang.org/x/net/httpgo1.11.13、go1.12.8
GO-2022-0535CVE-2020-0601Certificate validation bypass on Windows in crypto/x509go1.12.16、go1.13.7
GO-2022-0229CVE-2020-7919Panic in certificate parsing in crypto/x509 and golang.org/x/crypto/cryptobytego1.12.16、go1.13.7
GO-2022-0220CVE-2019-9634DLL injection on Windows in runtime and syscallgo1.11.10、go1.12.2
GO-2022-0213CVE-2019-17596Panic on invalid DSA public keys in crypto/dsago1.12.11、go1.13.2
GO-2022-0212CVE-2019-16276Request smuggling due to accepting invalid headers in net/http via net/textprotogo1.12.10、go1.13.1
GO-2022-0211CVE-2019-14809Incorrect parsing validation in net/urlgo1.11.13、go1.12.8

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

資料來源