0001-archive-tar-do-not-populate-user-group-names.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From bc0de86b495ae014b209431ed7cb90fc3d5e4d1f Mon Sep 17 00:00:00 2001
  2. From: Kir Kolyshkin <kolyshkin@gmail.com>
  3. Date: Mon, 9 Apr 2018 15:58:40 -0700
  4. Subject: [PATCH] archive/tar: do not populate user/group names
  5. This reverts part of commit 29a18899379c ("archive/tar: populate
  6. uname/gname/devmajor/devminor in FileInfoHeader"). The reason is
  7. using os/user functions to resolved uids/gids to names breaks
  8. the static build for Linux/glibc case (the resulting binary panics
  9. on NULL pointer dereference).
  10. For much more details, see https://github.com/golang/go/issues/23265
  11. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  12. ---
  13. src/archive/tar/stat_unix.go | 26 +++-----------------------
  14. 1 file changed, 3 insertions(+), 23 deletions(-)
  15. diff --git a/src/archive/tar/stat_unix.go b/src/archive/tar/stat_unix.go
  16. index 868105f338..9640ed4bab 100644
  17. --- a/src/archive/tar/stat_unix.go
  18. +++ b/src/archive/tar/stat_unix.go
  19. @@ -8,10 +8,7 @@ package tar
  20. import (
  21. "io/fs"
  22. - "os/user"
  23. "runtime"
  24. - "strconv"
  25. - "sync"
  26. "syscall"
  27. )
  28. @@ -19,10 +16,6 @@ func init() {
  29. sysStat = statUnix
  30. }
  31. -// userMap and groupMap caches UID and GID lookups for performance reasons.
  32. -// The downside is that renaming uname or gname by the OS never takes effect.
  33. -var userMap, groupMap sync.Map // map[int]string
  34. -
  35. func statUnix(fi fs.FileInfo, h *Header) error {
  36. sys, ok := fi.Sys().(*syscall.Stat_t)
  37. if !ok {
  38. @@ -31,22 +24,9 @@ func statUnix(fi os.FileInfo, h *Header) error {
  39. h.Uid = int(sys.Uid)
  40. h.Gid = int(sys.Gid)
  41. - // Best effort at populating Uname and Gname.
  42. - // The os/user functions may fail for any number of reasons
  43. - // (not implemented on that platform, cgo not enabled, etc).
  44. - if u, ok := userMap.Load(h.Uid); ok {
  45. - h.Uname = u.(string)
  46. - } else if u, err := user.LookupId(strconv.Itoa(h.Uid)); err == nil {
  47. - h.Uname = u.Username
  48. - userMap.Store(h.Uid, h.Uname)
  49. - }
  50. - if g, ok := groupMap.Load(h.Gid); ok {
  51. - h.Gname = g.(string)
  52. - } else if g, err := user.LookupGroupId(strconv.Itoa(h.Gid)); err == nil {
  53. - h.Gname = g.Name
  54. - groupMap.Store(h.Gid, h.Gname)
  55. - }
  56. -
  57. + // TODO(bradfitz): populate username & group. os/user
  58. + // doesn't cache LookupId lookups, and lacks group
  59. + // lookup functions.
  60. h.AccessTime = statAtime(sys)
  61. h.ChangeTime = statCtime(sys)
  62. base-commit: 4af1337d1e9eb9e7b766c9deb787c78413bb25c4
  63. --
  64. 2.24.1