Bug 244204 - ports-mgmt/dialog4ports - Segmentation fault after upgrade to 13.x-currrent
Summary: ports-mgmt/dialog4ports - Segmentation fault after upgrade to 13.x-currrent
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Dmitry Marakasov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-17 22:30 UTC by Garance A Drosehn
Modified: 2021-09-09 20:03 UTC (History)
4 users (show)

See Also:
amdmi3: maintainer-feedback+


Attachments
12.x executable and core file (56.27 KB, application/octet-stream)
2020-02-18 19:19 UTC, Garance A Drosehn
no flags Details
12.x executable (-gO2) and core file (70.70 KB, application/octet-stream)
2020-02-19 04:05 UTC, Garance A Drosehn
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Garance A Drosehn freebsd_committer 2020-02-17 22:30:08 UTC
I have one virtual machine running 12.x:

FreeBSD <my.host12.edu> 12.1-STABLE FreeBSD 12.1-STABLE r357988 VM-Gilead-12x  amd64

I removed all ports, and reinstalled them.  Most of them are compiled via portupgrade, with just a few brought in via 'pkg install'.

I shutdown the VM, duplicated to a new VM, and then upgraded that VM to be running 13.x:

FreeBSD <my.host13.edu> 13.0-CURRENT FreeBSD 13.0-CURRENT #0 r357988: Sun Feb 16 02:16:34 EST 2020     root@<my.host13.edu>:/usr/obj/usr/src/amd64.amd64/sys/VM-Gilead-13x  amd64

I use portsnap to update all of its data, and it recommends that I do a 'pkg bootstrap -f' before doing anything else.  So I do that.

Later on I use 'pkg version -vL =' and discover there are several ports which need to be upgraded.  I start upgrading them, and (to make a long story short) I notice that if an 'config' dialog box comes up, that I sometimes see it followed by:

`Segmentation fault (core dumped)
 ===> Options unchanged'

I think the core dump happens only if I did not change any options when that dialog box came up.  I determined it was the program 'dialog4ports' which was core-dumping with the segmentation fault.  I could 'cd' into the directory for some port, do a 'make config', hit the enter key (thus approving the current options without changing any), and it would core-dump.

To solve this, I did:

`cd /usr/ports/ports-mgmt/dialog4ports
 make config && make
 make deinstall && make install
 make clean'

After doing this, I see no more problems with segmentation faults when running dialog4ports.  And if I copy the dialog4ports program from my 12.x system to my 13.x system, those segmentation faults will reappear.

So far I have not noticed any problems with any other ports after moving from 12.x to 13.x, but then there are many port-executables which I have not run since that upgrade.  I considered removing all ports and rebuilding all of them on 13.x, but I haven't had the time to just yet.

Perhaps when the system notices that a major OS-level upgrade has occurred, the 'pkg bootstrap -f' step should update 'dialog4ports' in addition to 'pkg' itself?
Comment 1 ru_M1cRO 2020-02-17 23:04:27 UTC
Hi Garance,

Do you have core file?
Actually d4p was not changed between 12-13, and it can be related with changes in libdialog.
Maybe you can give me you dialog4ports from your 12bsd? (for future investigating)
Comment 2 Garance A Drosehn freebsd_committer 2020-02-18 19:19:16 UTC
Created attachment 211747 [details]
12.x executable and core file
Comment 3 Garance A Drosehn freebsd_committer 2020-02-18 19:24:25 UTC
I can generate core files at will by using the version of dialog4ports from my 12.x system on my 13.x system.  Here is a ssh-session on my 13.x system, with a few blank lines removed.  I didn't notice it before, but it is perhaps interesting that the run which sees the segmentation fault *does* print out '===> Options unchanged', while the one without a seg-fault does not print anything.

# ————————————————————————————————————————————————————
# ————————————————————————————————————————————————————
(1326) root # cp -p /usr/local/bin/dialog4ports{-12x,}
(1327) root # cd /usr/ports/security/libgpg-error
(1328) root # make config

  ┌────────────────────────── libgpg-error-1.37 ─────────────────────────────┐
  │ ┌──────────────────────────────────────────────────────────────────────┐ │
  │ │ [ ] DOCS  Build and/or install documentation                         │ │
  │ │ [x] NLS   Native Language Support                                    │ │
  │ │ [ ] TEST  Build and/or run tests                                     │ │
  │ └──────────────────────────────────────────────────────────────────────┘ │
  ├──────────────────────────────────────────────────────────────────────────┤
  │                       <  OK  >            <Cancel>                       │
  └──────────────────────────────────────────────────────────────────────────┘

Segmentation fault (core dumped)
===> Options unchanged
(1329) root # ls -l dialog4ports.core 
-rw-------  1 root  wheel  9744384 Feb 18 14:03 dialog4ports.core
(1330) root # cp -p /usr/local/bin/dialog4ports{-13x,}
(1331) root # make config

  ┌────────────────────────── libgpg-error-1.37 ─────────────────────────────┐
  │ ┌──────────────────────────────────────────────────────────────────────┐ │
  │ │ [ ] DOCS  Build and/or install documentation                         │ │
  │ │ [x] NLS   Native Language Support                                    │ │
  │ │ [ ] TEST  Build and/or run tests                                     │ │
  │ └──────────────────────────────────────────────────────────────────────┘ │
  ├──────────────────────────────────────────────────────────────────────────┤
  │                       <  OK  >            <Cancel>                       │
  └──────────────────────────────────────────────────────────────────────────┘

(1332) root # date
Tue Feb 18 14:04:19 EST 2020
(1333) root # mv dialog4ports.core /usr/local/bin/dialog4ports{-12x,} /tmp
(1334) root # cd /tmp
(1335) root # tar cjf dialog4ports-dbg.tbz2 dialog4ports-12x dialog4ports.core
Comment 4 ru_M1cRO 2020-02-18 23:39:03 UTC
Mmm, I can reproduce segfault with your d4p-12 on my 13bsd.
Can you build d4p-12 with debug symbols?
Comment 5 Garance A Drosehn freebsd_committer 2020-02-19 03:56:36 UTC
I can.  It took awhile though.

I built it with:  CFLAGS="-g -fstandalone-debug" make
and also with:    CFLAGS="-g" make
and both of those versions did *not* generate a seg-fault.

I then wondered if maybe there was something odd about the dialog4ports which I had been using on my 12x system (built back on Dec 24th).  I built a new one without debuginfo, and it did generate the seg-fault.

I then noticed that when I specify "-g", some makefile-magic somewhere changes what *other* options are given to clang.  In particular, adding "-g" causes "-O2 -pipe" to be removed, and that results in significantly different code.

So I built it with:  CFLAGS="-g -O2 -pipe" make
and that version does generate the seg-fault, and also does have the debugging info.
Comment 6 Garance A Drosehn freebsd_committer 2020-02-19 04:05:35 UTC
Created attachment 211754 [details]
12.x executable (-gO2) and core file

Created via:

cd /usr/ports/security/libgpg-error
make config
#       hit 'enter' without changing anything
mv dialog4ports.core /tmp
cp -p /usr/local/bin/dialog4ports /tmp/dialog4ports-12x-gO2
file /tmp/dialog4ports-12x-gO2

#   /tmp/dialog4ports-12x-gO2: ELF 64-bit LSB executable,
#   x86-64, version 1 (FreeBSD), dynamically linked,
#   interpreter /libexec/ld-elf.so.1, for FreeBSD 12.1 (1201512),
#   FreeBSD-style, with debug_info, not stripped

tar cjf dialog4ports-dbg-g.tbz2 dialog4ports-12x-gO2 dialog4ports.core
Comment 7 Garance A Drosehn freebsd_committer 2020-03-09 22:50:36 UTC
Note that I'm not sure that it's important to figure out the specific bug in this specific case.  I'm just saying it might be wise if the recommended step of:

pkg bootstrap -f

would also install a version of "dialog4ports" which matches the OS the user is running on.  Even if we can fix the specific issue that I ran into, I suspect there will be plenty of other opportunities for a similar problem to come up in the future.
Comment 8 Joshua Kinard 2020-12-30 00:59:28 UTC
This is reproducible if in certain 'make config' dialogs, you put the selection at the top of the list and then press the up arrow a few times.  Usually takes just once, but sometimes a few more.  It is easier to trigger on 'make config' dialogs that have enough options to make the list scrollable.  On those, pressing the up arrow once is usually enough to trigger the core dump.  I've been randomly running into this issue since 12.0-RELEASE, and it's still present in 12.2-RELEASE-p2.  Just triggered it in a 'make config' dialog in sysutils/openzfs by pressing up at the top of the three-item dialog list.
Comment 9 Joshua Kinard 2020-12-30 01:16:15 UTC
Looks like in my case, building dialog4ports from ports doesn't fix the issue.  Rebuilt it w/ debugging and got this backtrace out of gdb:

# gdb /usr/local/bin/dialog4ports dialog4ports.core
GNU gdb (GDB) 10.1 [GDB v10.1 for FreeBSD]
[snip]
Reading symbols from /usr/local/bin/dialog4ports...
[New LWP 100639]
Core was generated by `/usr/local/bin/dialog4ports'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000000000205c4a in dlg_mixedlist (title=0x7fffffa7c780 " openzfs-2020120100 ", cprompt=0x202026 "", height=9, min_height=0, width=80, item_no=3, items=0x86f4cd000, align_center=false, fullscreen=false) at mixedlist.c:655
655                                                     if (items[scrollamt + i].type == ITEM_SEPARATOR && (scrollamt + i) == 0)

(gdb) bt
#0  0x0000000000205c4a in dlg_mixedlist (title=0x7fffffa7c780 " openzfs-2020120100 ", cprompt=0x202026 "", height=9, min_height=0, width=80, item_no=3, items=0x86f4cd000, align_center=false, fullscreen=false) at mixedlist.c:655
#1  0x0000000000203fc3 in mixedlist_show (title=0x7fffffa7c780 " openzfs-2020120100 ", cprompt=0x202026 "", height=0, min_height=0, width=80, items=0x86f4cd000, align_center=false, fullscreen=false) at dialog4ports.c:212
#2  0x0000000000203ca2 in main (argc=0, argv=0x7fffffa7c8f8) at dialog4ports.c:321
(gdb)
Comment 10 ru_M1cRO 2020-12-30 09:46:57 UTC
(In reply to Joshua Kinard from comment #8)

Hi, what the d4p version you have?
dialog4ports -v
Comment 11 Joshua Kinard 2020-12-30 16:26:17 UTC
(In reply to ru_M1cRO from comment #10)

0.1.6
Comment 12 Joshua Kinard 2020-12-30 23:36:16 UTC
> Hi Joshua,
> Can you show bt full, it very interesting case because in 0.1.6 it was fixed >_<
> 30.12.2020, 19:26, "bugzilla-noreply@freebsd.org" <bugzilla-noreply@freebsd.org>:
> 
>     https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=244204
> 
>     --- Comment #11 from Joshua Kinard <kumba@gentoo.org
>     <mailto:kumba@gentoo.org>> ---
>     (In reply to ru_M1cRO from comment #10)
> 
>     0.1.6
> 
>     --
>     You are receiving this mail because:
>     You are on the CC list for the bug.
> 
> -- 
> With Best Regards,
> Ilya A. Arkhipov
> 


Here you go.  This is me using the steps provided in my earlier comment (pressing the up arrow once in sysutils/openzfs 'make config') to generate the crash.

# gdb /usr/local/bin/dialog4ports dialog4ports.core
GNU gdb (GDB) 10.1 [GDB v10.1 for FreeBSD]
[snip]
Reading symbols from /usr/local/bin/dialog4ports...
[New LWP 100605]
Core was generated by `/usr/local/bin/dialog4ports'.
Program terminated with signal SIGSEGV, Segmentation fault.

[snip]

(gdb) bt full
#0  0x0000000000205c4a in dlg_mixedlist (title=0x7fffff1c2ce0 " openzfs-2020120100 ", cprompt=0x202026 "", height=9, min_height=0, width=80, item_no=3, items=0x86c0f9000, align_center=false, fullscreen=false) at mixedlist.c:655
        binding = {{is_function_key = 0, curses_key = 10, dialog_key = 541}, {is_function_key = 0, curses_key = 13, dialog_key = 541}, {is_function_key = 1, curses_key = 343, dialog_key = 541}, {is_function_key = 1, curses_key = 261,
            dialog_key = 528}, {is_function_key = 0, curses_key = 9, dialog_key = 528}, {is_function_key = 1, curses_key = 353, dialog_key = 529}, {is_function_key = 1, curses_key = 260, dialog_key = 529}, {is_function_key = 1,
            curses_key = 262, dialog_key = 522}, {is_function_key = 1, curses_key = 360, dialog_key = 523}, {is_function_key = 1, curses_key = 347, dialog_key = 523}, {is_function_key = 0, curses_key = 43, dialog_key = 524}, {
            is_function_key = 1, curses_key = 258, dialog_key = 524}, {is_function_key = 0, curses_key = 14, dialog_key = 524}, {is_function_key = 0, curses_key = 45, dialog_key = 525}, {is_function_key = 1, curses_key = 259,
            dialog_key = 525}, {is_function_key = 0, curses_key = 16, dialog_key = 525}, {is_function_key = 1, curses_key = 338, dialog_key = 520}, {is_function_key = 1, curses_key = 1106, dialog_key = 520}, {is_function_key = 1,
            curses_key = 339, dialog_key = 521}, {is_function_key = 1, curses_key = 1107, dialog_key = 521}, {is_function_key = -1, curses_key = 0, dialog_key = 0}}
        old_height = 0
        old_width = 80
        i = -1
        j = 0
        key2 = 2135968
        x = 77
        y = 21
        cur_x = 49
        cur_y = 0
        box_x = 2
        box_y = 1
        key = 525
        fkey = 525
        button = 0
        choice = 0
        scrollamt = 0
        max_choice = 3
        was_mouse = 0
        use_height = 3
        use_width = 68
        name_width = 6
        text_width = 62
        result = -2
        dialog = 0x81d7662b0
        list = 0x81d766390
        prompt = 0x805152058 ""
        buttons = 0x801fa16a0
        found = true
        group = 0

#1  0x0000000000203fc3 in mixedlist_show (title=0x7fffff1c2ce0 " openzfs-2020120100 ", cprompt=0x202026 "", height=0, min_height=0, width=80, items=0x86c0f9000, align_center=false, fullscreen=false) at dialog4ports.c:212
        res = 33091533

#2  0x0000000000203ca2 in main (argc=0, argv=0x7fffff1c2e58) at dialog4ports.c:321
        portname = 0x7fffffffec92 "openzfs-2020120100"
        temp = 0x0
        buf = " openzfs-2020120100 \000\177", '\000' <repeats 18 times>, "X\255\036\003;<\000\000\000\200=\000\b\000\000\000\177\003\034ÿÿ\177\000\000ž0\034ÿÿ\177\000\000è0\034ÿÿ\177\000\000\000\000\000\000ÿ\177\000\000\000À=\000\b\000\000\000È\224 \000\000\000\000\000h\026 \000\000\000\000\000\000\200=\000\b", '\000' <repeats 11 times>, "`.\034ÿÿ\177\000\000\000\000\000\000\000\000\000\000P.\034ÿÿ\177\000\000\001\000\000\000\000\000\000\000\t\037\003\266É9\220|\240\227 \000\000\000\000\000`.\034ÿÿ\177\000\000\000\000\000\000\000\000\000\000P.\034ÿÿ\177\000\000"...
        i = 8
        res = 51093712
        ch = -1
        height = 0
        width = 80
        min_height = 0
        align_center = false
        fullscreen = false
        helpfile = 0x0
        items = 0x86c0f9000
(gdb)
Comment 13 Joshua Kinard 2021-01-06 01:23:16 UTC
> Hi Joshua,
> Can you try attached patch?
> Need put it into /usr/ports/ports-mgmt/dialog4ports/files and rebuild d4p like 
> make -C /usr/ports/ports-mgmt/dialog4ports clean build deinstall install
> Actually, I still cant reproduce problem ;(
> Thanks in advance.
> 
> --- mixedlist.c_old	2021-01-03 16:01:52.851092000 +0300
> +++ mixedlist.c	2021-01-03 16:06:04.266150000 +0300
> @@ -652,12 +652,12 @@
>  						break;
>  					case DLGK_ITEM_PREV:
>  						i = choice - 1;
> +						if (choice == 0 && scrollamt == 0)
> +							continue;
>  						if (items[scrollamt + i].type == ITEM_SEPARATOR && (scrollamt + i) == 0)
>  							i++;
>  						else if (items[scrollamt + i].type == ITEM_SEPARATOR)
>  							i--;
> -						if (choice == 0 && scrollamt == 0)
> -							continue;
>  						break;
>  					case DLGK_ITEM_NEXT:
>  						i = choice + 1;> 
> -- 
> With Best Regards,
> Ilya A. Arkhipov

Just rebuilt dialog4ports with this patch, and the issue is not reproducible anymore.

Not sure what's different about my environment, but I can tell you some parameters and maybe one of them is a factor:

  - PuTTY v0.74 from a Windows desktop to the FreeBSD system
  - Shell is /usr/local/bin/bash
  - TERM is xterm-256color
  - LANG is en_US.ISO8859-15
  - MM_CHARSET is ISO-8859-15
  - /usr/ports is mounted over NFSv4.1 onto the target system (the NFS server also runs FreeBSD and reproduces the same issue locally)
Comment 14 Dmitry Marakasov freebsd_committer 2021-02-18 21:00:32 UTC
Ilya, should we maybe commit the patch?
Comment 15 ru_M1cRO 2021-02-18 21:03:54 UTC
(In reply to Dmitry Marakasov from comment #14)
Hi Dmitry,
Let me please few days for prepare new d4p version.
Comment 16 Dmitry Marakasov freebsd_committer 2021-03-29 14:36:16 UTC
(In reply to ru_M1cRO from comment #15)
Ping?
Comment 17 Graham Perrin 2021-05-09 14:19:22 UTC
Drive-by comment from a user of 14.0-CURRENT: after removing poudriere-devel then installing poudriere, the (automatically reinstalled) dialog4ports ran _without_ a segmentation fault. 

From /var/log/messages :

…
May  9 15:10:45 mowa219-gjp4-8570p kernel: pid 65454 (dialog4ports), jid 0, uid 0: exited on signal 11 (core dumped)
May  9 15:11:09 mowa219-gjp4-8570p pkg[65926]: poudriere-devel-3.3.99.20210303_2 deinstalled
May  9 15:11:09 mowa219-gjp4-8570p pkg[65926]: dialog4ports-0.1.6 deinstalled
May  9 15:11:45 mowa219-gjp4-8570p pkg[65937]: dialog4ports-0.1.6 installed
May  9 15:11:46 mowa219-gjp4-8570p pkg[65937]: poudriere-3.3.6 installed
…
Comment 18 commit-hook freebsd_committer 2021-09-09 20:03:20 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=9e7bd94765c2ae7bc47d40abf56da5ae412f9f5f

commit 9e7bd94765c2ae7bc47d40abf56da5ae412f9f5f
Author:     Dmitry Marakasov <amdmi3@FreeBSD.org>
AuthorDate: 2021-09-09 19:56:11 +0000
Commit:     Dmitry Marakasov <amdmi3@FreeBSD.org>
CommitDate: 2021-09-09 20:02:40 +0000

    ports-mgmt/dialog4ports: fix segfault

    Fix segfault when moving selection in some dialog configurations

    Reported by:    gad, kumba@gentoo.org
    Submitted by:   rum1cro@yandex.ru (maintainer)
    PR:             244204

 ports-mgmt/dialog4ports/Makefile                      |  2 +-
 ports-mgmt/dialog4ports/files/patch-mixedlist.c (new) | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)