Bug 207694 - ports-mgmt/pkg: 'pkg version -x' crashes when using /usr/ports which doesn't have INDEX-* files
Summary: ports-mgmt/pkg: 'pkg version -x' crashes when using /usr/ports which doesn't ...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-pkg (Nobody)
URL:
Keywords: crash, needs-qa
Depends on:
Blocks:
 
Reported: 2016-03-04 08:11 UTC by Marko Turk
Modified: 2016-04-04 06:57 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (pkg)
koobs: maintainer-feedback? (mt-bugs)
koobs: merge-quarterly?


Attachments
pkg -vvv output (2.47 KB, text/plain)
2016-03-04 08:29 UTC, Marko Turk
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marko Turk 2016-03-04 08:11:00 UTC
Hi,

if you populate /usr/ports but remove INDEX-* files from it (or checkout it from svn, then INDEX-* files are not there), then 'pkg version -x not-existing-package' crashes:
Child process pid=5172 terminated abnormally: Segmentation fault

This only happens when /usr/ports is populated but /usr/ports/INDEX-* files are NOT present.

BR,
Marko
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2016-03-04 08:16:46 UTC
Thank you for your report

What version of FreeBSD?
Please include `uname -a` output

What version of pkg is running? 
Please include pkg -vvv output as an attachment

Did this work prior to a particular version, or before the version you are using?

Additionally, if you could provide a debugging backtrace of the pkg{-static}.core file using gdb (bt command), that might assist isolating the issue.
Comment 2 Marko Turk 2016-03-04 08:29:28 UTC
Hi,

it's easy to reproduce, I reproduced this on both:
FreeBSD shkatula 10.3-BETA3 FreeBSD 10.3-BETA3 #0 r296341: Thu Mar  3 10:54:35 CET 2016     root@shkatula:/usr/obj/usr/src/sys/GENERIC  amd64

FreeBSD fte 10.2-RELEASE-p5 FreeBSD 10.2-RELEASE-p5 #0: Thu Sep 24 01:06:05 CEST 2015     root@fte:/usr/obj/usr/src/sys/GENERIC  i386

I'm not sure when it started failing, I just noticed it now.

I'll attach pkg -vvv.

GDB backtrace:
Core was generated by `pkg'.
Program terminated with signal 11, Segmentation fault.
#0  0x000000000041aa79 in ?? ()
(gdb) bt
#0  0x000000000041aa79 in ?? ()
#1  0x0000000000000000 in ?? ()
(gdb)

BR,
Marko
Comment 3 Marko Turk 2016-03-04 08:29:49 UTC
Created attachment 167705 [details]
pkg -vvv output
Comment 4 Kubilay Kocak freebsd_committer freebsd_triage 2016-03-04 08:34:46 UTC
Could you try rebuilding pkg WITH_DEBUG=yes (adds -g to CFLAGS and prevents stripping), and try the backtrace again (as attachment)

Thanks!
Comment 5 Marko Turk 2016-03-04 09:24:53 UTC
After WITH_DEBUG=yes pkg binary is still stripped, I must've done something wrong.

But I managed to get usable core dump with pkg-static:
Core was generated by `pkg-static'.
Program terminated with signal 11, Segmentation fault.
#0  0x0806abe6 in free_categories () at version.c:359
359             kh_foreach_value(categories, cat, {
(gdb) bt
#0  0x0806abe6 in free_categories () at version.c:359
#1  0x0806a74e in do_source_ports (opt=1024, limchar=45 '-', pattern=0xbfbfee32 "aaaaaaa", match=MATCH_REGEX, matchorigin=0x0, matchname=0x0, portsdir=0x28c04160 "/usr/ports")
    at version.c:781
#2  0x08069698 in exec_version (argc=0, argv=0xbfbfed00) at version.c:997
#3  0x0805926e in main (argc=3, argv=0xbfbfecf4) at main.c:852

BR,
Marko
Comment 6 Marko Turk 2016-03-04 09:34:55 UTC
The problem is probably in version.c:359:

if (categories == NULL)
    return;

should be added.
Comment 7 Baptiste Daroussin freebsd_committer freebsd_triage 2016-03-06 13:01:22 UTC
Fixed in master will be in 1.6.5 thanks!