LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   nvi segfaults in command edit and CFLAGS aren't set properly SlackBuild (-current) (https://www.linuxquestions.org/questions/slackware-14/nvi-segfaults-in-command-edit-and-cflags-arent-set-properly-slackbuild-current-4175693589/)

kaott 04-12-2021 11:05 PM

nvi segfaults in command edit and CFLAGS aren't set properly SlackBuild (-current)
 
Howdy,
nvi has a repeatable segfault in command history (cedit) mode. I haven't been able to track it down as to why yet. In part of trying to figure it out it looks like the SlackBuild also isn't setting the CFLAGS properly, as they don't seem to be picked up properly. I think it should be OPTFLAGS="$SLKCFLAGS" instead of CFLAGS, doing this I can at least see the SLKCFLAGS in the compiler invocations when make is called.

Back to the segfault

What I have in my ~/.nexrc :
Code:

set cedit=^V^V^V^I
(that is control-v control-v control-v control-tab if trying to enter it in while in nvi)
That is to set it so when I have the ex command prompt up I can hit tab and it will bring up the command history. This works as expected, but you can't do much while in the command history, nvi will segfault if you try to edit a command.

I had rebuilt the nvi package with some debugging flags enabled, and it looks like the ultimate point of the segfault is somewhere in the db48 library when it is doing a memmove. I had also rebuilt the db48 library with some debugging flags enabled, but this didn't help much. I tried building it with -fsanitize=address, but it basically bailed out at launch :)

Here is the stack trace from a stock nvi and stock db48 package:
Code:

#0  0x00007ffff7c1c241 in __memmove_sse2_unaligned_erms () from /lib64/libc.so.6
#1  0x00007ffff7e2b42c in __db_poff () from /lib64/libdb-4.8.so
#2  0x00007ffff7d84702 in __bam_iitem () from /lib64/libdb-4.8.so
#3  0x00007ffff7d8bb11 in ?? () from /lib64/libdb-4.8.so
#4  0x00007ffff7e191b2 in __dbc_iput () from /lib64/libdb-4.8.so
#5  0x00007ffff7e0e65a in __db_put () from /lib64/libdb-4.8.so
#6  0x00007ffff7e25278 in __db_put_pp () from /lib64/libdb-4.8.so
#7  0x00007ffff7f5e905 in db_set () from /usr/lib64/libvi.so.0
#8  0x00007ffff7f721b7 in v_txt () from /usr/lib64/libvi.so.0
#9  0x00007ffff7f6aa9e in v_ia () from /usr/lib64/libvi.so.0
#10 0x00007ffff7f76683 in vi () from /usr/lib64/libvi.so.0
#11 0x00007ffff7f5fa95 in editor () from /usr/lib64/libvi.so.0
#12 0x0000000000403b6a in ?? ()
#13 0x00007ffff7b911ad in __libc_start_main () from /lib64/libc.so.6
#14 0x00000000004025aa in ?? ()

Does anyone have any ideas on how to investigate this further?

notzed 04-13-2021 06:05 PM

You're right on CFLAGS - dist/Makefile.am in nvi is broken and overrides it with OPTFLAG. I think you still need to set CFLAGS to configure but could pass in OPTFLAG to make (OPTFLAG="$SLKCFLAGS" make), but ideally you should ask the author to fix the Makefile.am (or probably patch it in the slackbuild given it hasn't been updated in 14 years).

For debugging memory problems of c programs valgrind is the tool to use. It's somewhat complex but just running 'valgrind nvm' will get you something. For more useful output ensure the binaries and libraries are compiled in debug mode and not stripped (--enable-debug to configure does it for nvi).

valgrind might produce a lot of output so use --log-file=log as well. valgrind will mean it wont likely crash but just report the segfault and keep going.

nvi wont build on slackware64-current fwiw.

shruggy 04-13-2021 06:23 PM

FWIW, this is how I build nvi on CentOS 8 (part of my nvi.spec):
Code:

(cd build.unix
OPTFLAG="${CFLAGS:-%optflags}" \
ADDLDFLAGS="${LDFLAGS:-%__global_ldflags}" \
ac_cv_path_vi_cv_path_sendmail=/usr/sbin/sendmail \
vi_cv_revoke=no \
../dist/configure \
  --prefix=%{_prefix} --datadir=%{_datadir} --mandir=%{_mandir} \
  --disable-curses \
  --disable-shared --enable-static \
  --enable-widechar \
  --disable-threads \
  --without-x \
  --with-gnu-ld=yes \
  --program-prefix=n
)

%optflags and %__global_ldflags are Fedora-specific RPM macros defined thusly:
Code:

$ rpm -E %optflags
-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
$
rpm -E %__global_ldflags
-Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld



All times are GMT -5. The time now is 07:12 AM.