[Bug 284276] ports-mgmt/pkg: 'version' command often segfaults when used with -o option after upgrading to pkg-2.0.0

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 23 Jan 2025 08:59:27 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=284276

--- Comment #2 from Ale <discipline@tiscali.it> ---
I noticed that this is happening with both /usr/sbin/pkg and
/usr/local/sbin/pkg, 
$ ls -latr /usr/local/sbin/pkg /usr/sbin/pkg 
-r-xr-xr-x  1 root wheel    35880 Dec 14 12:51 /usr/sbin/pkg
-rwxr-xr-x  1 root wheel  4229024 Jan 23 07:01 /usr/local/sbin/pkg
$ /usr/sbin/pkg version -o -n linux-quake4
Child process pid=59742 terminated abnormally: Segmentation fault
$ /usr/local/sbin/pkg version -o -n linux-quake4
Child process pid=59831 terminated abnormally: Segmentation fault
$ uname -Kvm
FreeBSD 14.2-STABLE 9bc9cf4a2 STARLESS amd64 1402501
but I'm pretty sure it started crashing since yesterday, after upgrading
ports-mgmt/pkg (in my case pkg is an alias for the latter).

I tried rebuilding the port WITH_DEBUG and...
# ./work/stage/usr/local/sbin/pkg version -o -n linux-quake4
Child process pid=59543 terminated abnormally: Segmentation fault
# lldb ./work/stage/usr/local/sbin/pkg --core /usr/ports/pkg.core
(lldb) target create "./work/stage/usr/local/sbin/pkg" --core
"/usr/ports/pkg.core"
Core file '/usr/ports/pkg.core' (x86_64) was loaded.
(lldb) bt
* thread #1, name = 'pkg', stop reason = signal SIGSEGV
  * frame #0: 0x000000000058d504 pkg`format_comment(buf=0x000026d13d24c480,
data=0x000000000000003e, p=0x000026d13d22a400) at pkg_printf.c:1617:31
    frame #1: 0x000000000058b578
pkg`process_format_main(buf=0x000026d13d24c480, p=0x000026d13d22a400,
fstart="", fend="", data=0x000000000000003e) at pkg_printf.c:2900:6
    frame #2: 0x000000000058ac28
pkg`pkg_xstring_vprintf(buf=0x000026d13d24c480, format="",
ap=0x00000008210f2270) at pkg_printf.c:3191:8
    frame #3: 0x000000000058a9f1 pkg`pkg_vprintf(format="",
ap=0x00000008210f2270) at pkg_printf.c:2942:9
    frame #4: 0x000000000058a98b pkg`pkg_printf(format="") at
pkg_printf.c:2921:10
    frame #5: 0x000000000032098c pkg`print_version(pkg=0x000026d13d316000,
source="", ver="1.4.2_1,1", limchar='-', opt=9218) at version.c:117:3
    frame #6: 0x0000000000320346 pkg`do_source_ports(opt=9218, limchar='-',
pattern=0x0000000000000000, match=MATCH_ALL, matchorigin=0x0000000000000000,
matchname="linux-quake4", portsdir="/usr/ports") at version.c:773:3
    frame #7: 0x000000000031f63f pkg`exec_version(argc=0,
argv=0x00000008210f3240) at version.c:1008:11
    frame #8: 0x0000000000310591 pkg`main(argc=4, argv=0x00000008210f3220) at
main.c:809:9
    frame #9: 0x00000008262191c4 libc.so.7`__libc_start1(argc=5,
argv=0x00000008210f3218, env=0x00000008210f3248, cleanup=<unavailable>,
mainX=(pkg`main at main.c:489)) at libc_start1.c:157:7
    frame #10: 0x0000000000301f80 pkg`_start at crt1_s.S:83
(lldb) f 0
frame #0: 0x000000000058d504 pkg`format_comment(buf=0x000026d13d24c480,
data=0x000000000000003e, p=0x000026d13d22a400) at pkg_printf.c:1617:31
   1614 {
   1615         const struct pkg        *pkg = data;
   1616 
-> 1617         return (string_val(buf, pkg->comment, p));
   1618 }
   1619 
   1620 /*
(lldb) p *buf
(xstring) {
  buf = 0x000026d13d208248 ""
  size = 0
  fp = 0x000000082638a178
}
(lldb) p *p
(percent_esc) {
  flags = 0
  width = 0
  trailer_status = 0
  item_fmt = 0x000026d13d252780
  sep_fmt = 0x000026d13d2527c0
  fmt_code = PP_PKG_COMMENT
}
(lldb) frame var *pkg
(const pkg) *pkg = {
  direct = <read memory from 0x3e failed (0 of 1 bytes read)>

  locked = <read memory from 0x3f failed (0 of 1 bytes read)>

  automatic = <read memory from 0x40 failed (0 of 1 bytes read)>

  vital = <read memory from 0x41 failed (0 of 1 bytes read)>

  id = <read memory from 0x46 failed (0 of 8 bytes read)>

  scripts = {
    [0] = <read memory from 0x4e failed (0 of 8 bytes read)>

    [1] = <read memory from 0x56 failed (0 of 8 bytes read)>

    [2] = <read memory from 0x5e failed (0 of 8 bytes read)>

    [3] = <read memory from 0x66 failed (0 of 8 bytes read)>

    [4] = <read memory from 0x6e failed (0 of 8 bytes read)>

    [5] = <read memory from 0x76 failed (0 of 8 bytes read)>

    [6] = <read memory from 0x7e failed (0 of 8 bytes read)>

    [7] = <read memory from 0x86 failed (0 of 8 bytes read)>

    [8] = <read memory from 0x8e failed (0 of 8 bytes read)>

  }
  lua_scripts = {
    [0] = {
      head = <read memory from 0x96 failed (0 of 8 bytes read)>

      tail = <read memory from 0x9e failed (0 of 8 bytes read)>

      length = <read memory from 0xa6 failed (0 of 8 bytes read)>

    }
    [1] = {
      head = <read memory from 0xae failed (0 of 8 bytes read)>

      tail = <read memory from 0xb6 failed (0 of 8 bytes read)>

      length = <read memory from 0xbe failed (0 of 8 bytes read)>

    }
    [2] = {
      head = <read memory from 0xc6 failed (0 of 8 bytes read)>

      tail = <read memory from 0xce failed (0 of 8 bytes read)>

      length = <read memory from 0xd6 failed (0 of 8 bytes read)>

    }
    [3] = {
      head = <read memory from 0xde failed (0 of 8 bytes read)>

      tail = <read memory from 0xe6 failed (0 of 8 bytes read)>

      length = <read memory from 0xee failed (0 of 8 bytes read)>

    }
    [4] = {
      head = <read memory from 0xf6 failed (0 of 8 bytes read)>

      tail = <read memory from 0xfe failed (0 of 8 bytes read)>

      length = <read memory from 0x106 failed (0 of 8 bytes read)>

    }
  }
  name = <read memory from 0x10e failed (0 of 8 bytes read)>

  origin = <read memory from 0x116 failed (0 of 8 bytes read)>

  version = <read memory from 0x11e failed (0 of 8 bytes read)>

  old_version = <read memory from 0x126 failed (0 of 8 bytes read)>

  maintainer = <read memory from 0x12e failed (0 of 8 bytes read)>

  www = <read memory from 0x136 failed (0 of 8 bytes read)>

  altabi = <read memory from 0x13e failed (0 of 8 bytes read)>

  abi = <read memory from 0x146 failed (0 of 8 bytes read)>

  uid = <read memory from 0x14e failed (0 of 8 bytes read)>

  digest = <read memory from 0x156 failed (0 of 8 bytes read)>

  old_digest = <read memory from 0x15e failed (0 of 8 bytes read)>

  message = {
    head = <read memory from 0x166 failed (0 of 8 bytes read)>

    tail = <read memory from 0x16e failed (0 of 8 bytes read)>

    length = <read memory from 0x176 failed (0 of 8 bytes read)>

  }
  prefix = <read memory from 0x17e failed (0 of 8 bytes read)>

  oprefix = <read memory from 0x186 failed (0 of 8 bytes read)>

  comment = <read memory from 0x18e failed (0 of 8 bytes read)>

  desc = <read memory from 0x196 failed (0 of 8 bytes read)>

  sum = <read memory from 0x19e failed (0 of 8 bytes read)>

  repopath = <read memory from 0x1a6 failed (0 of 8 bytes read)>

  reponame = <read memory from 0x1ae failed (0 of 8 bytes read)>

  repourl = <read memory from 0x1b6 failed (0 of 8 bytes read)>

  reason = <read memory from 0x1be failed (0 of 8 bytes read)>

  dep_formula = <read memory from 0x1c6 failed (0 of 8 bytes read)>

  licenselogic = <read memory from 0x1ce failed (0 of 4 bytes read)>

  pkgsize = <read memory from 0x1d6 failed (0 of 8 bytes read)>

  flatsize = <read memory from 0x1de failed (0 of 8 bytes read)>

  old_flatsize = <read memory from 0x1e6 failed (0 of 8 bytes read)>

  timestamp = <read memory from 0x1ee failed (0 of 8 bytes read)>

  depshash = <read memory from 0x1f6 failed (0 of 8 bytes read)>

  depends = <read memory from 0x1fe failed (0 of 8 bytes read)>

  rdepshash = <read memory from 0x206 failed (0 of 8 bytes read)>

  rdepends = <read memory from 0x20e failed (0 of 8 bytes read)>

  categories = {
    head = <read memory from 0x216 failed (0 of 8 bytes read)>

    tail = <read memory from 0x21e failed (0 of 8 bytes read)>

    length = <read memory from 0x226 failed (0 of 8 bytes read)>

  }
  licenses = {
    head = <read memory from 0x22e failed (0 of 8 bytes read)>

    tail = <read memory from 0x236 failed (0 of 8 bytes read)>

    length = <read memory from 0x23e failed (0 of 8 bytes read)>

  }
  filehash = <read memory from 0x246 failed (0 of 8 bytes read)>

  files = <read memory from 0x24e failed (0 of 8 bytes read)>

  dirhash = <read memory from 0x256 failed (0 of 8 bytes read)>

  dirs = <read memory from 0x25e failed (0 of 8 bytes read)>

  optionshash = <read memory from 0x266 failed (0 of 8 bytes read)>

  options = <read memory from 0x26e failed (0 of 8 bytes read)>

  users = {
    head = <read memory from 0x276 failed (0 of 8 bytes read)>

    tail = <read memory from 0x27e failed (0 of 8 bytes read)>

    length = <read memory from 0x286 failed (0 of 8 bytes read)>

  }
  groups = {
    head = <read memory from 0x28e failed (0 of 8 bytes read)>

    tail = <read memory from 0x296 failed (0 of 8 bytes read)>

    length = <read memory from 0x29e failed (0 of 8 bytes read)>

  }
  shlibs_required = {
    head = <read memory from 0x2a6 failed (0 of 8 bytes read)>

    tail = <read memory from 0x2ae failed (0 of 8 bytes read)>

    length = <read memory from 0x2b6 failed (0 of 8 bytes read)>

  }
  shlibs_provided = {
    head = <read memory from 0x2be failed (0 of 8 bytes read)>

    tail = <read memory from 0x2c6 failed (0 of 8 bytes read)>

    length = <read memory from 0x2ce failed (0 of 8 bytes read)>

  }
  conflictshash = <read memory from 0x2d6 failed (0 of 8 bytes read)>

  conflicts = <read memory from 0x2de failed (0 of 8 bytes read)>

  provides = {
    head = <read memory from 0x2e6 failed (0 of 8 bytes read)>

    tail = <read memory from 0x2ee failed (0 of 8 bytes read)>

    length = <read memory from 0x2f6 failed (0 of 8 bytes read)>

  }
  requires = {
    head = <read memory from 0x2fe failed (0 of 8 bytes read)>

    tail = <read memory from 0x306 failed (0 of 8 bytes read)>

    length = <read memory from 0x30e failed (0 of 8 bytes read)>

  }
  config_files_hash = <read memory from 0x316 failed (0 of 8 bytes read)>

  config_files = <read memory from 0x31e failed (0 of 8 bytes read)>

  annotations = {
    head = <read memory from 0x326 failed (0 of 8 bytes read)>

    tail = <read memory from 0x32e failed (0 of 8 bytes read)>

    length = <read memory from 0x336 failed (0 of 8 bytes read)>

  }
  flags = <read memory from 0x33e failed (0 of 4 bytes read)>

  rootfd = <read memory from 0x342 failed (0 of 4 bytes read)>

  rootpath = ""
  dir_to_del = {
    head = <read memory from 0x746 failed (0 of 8 bytes read)>

    tail = <read memory from 0x74e failed (0 of 8 bytes read)>

    length = <read memory from 0x756 failed (0 of 8 bytes read)>

  }
  type = <read memory from 0x75e failed (0 of 4 bytes read)>

  repo = <read memory from 0x766 failed (0 of 8 bytes read)>

}

Let me know if i can do any other test that might help.

-- 
You are receiving this mail because:
You are the assignee for the bug.