且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

[20151215]bvi使用问题.txt

更新时间:2022-09-10 16:19:35

[20151215]bvi使用问题.txt

--今天在linux上使用bvi遇到一个奇怪的问题。执行bvi查看文件会出现如下提示,注意实际上斜着(锯齿)显示的,我做了格式化。

# cat /etc/issue
Oracle Linux Server release 5.9
Kernel \r on an \m

$ bvi aa

"aa"*** buffer overflow detected ***: bvi terminated
======= Backtrace: =========
/lib64/libc.so.6(__chk_fail+0x2f)[0x37990e8ccf]
/lib64/libc.so.6[0x37990e7ca3]
bvi[0x40903e]
bvi[0x4090e4]
bvi[0x409137]
bvi[0x408a5a]
bvi[0x4027df]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x379901d9c4]
bvi[0x4019d9]
======= Memory map: ========
00400000-0040f000 r-xp 00000000 68:02 3355449                            /usr/bin/bvi
0060e000-00610000 rw-p 0000e000 68:02 3355449                            /usr/bin/bvi
00610000-00611000 rw-p 00000000 00:00 0
0080f000-00810000 rw-p 0000f000 68:02 3355449                            /usr/bin/bvi
00afb000-00b7f000 rw-p 00000000 00:00 0                                  [heap]
3798c00000-3798c1c000 r-xp 00000000 68:02 12190040                       /lib64/ld-2.5.so
3798e1c000-3798e1d000 r--p 0001c000 68:02 12190040                       /lib64/ld-2.5.so
3798e1d000-3798e1e000 rw-p 0001d000 68:02 12190040                       /lib64/ld-2.5.so
3799000000-379914f000 r-xp 00000000 68:02 12190041                       /lib64/libc-2.5.so
379914f000-379934f000 ---p 0014f000 68:02 12190041                       /lib64/libc-2.5.so
379934f000-3799353000 r--p 0014f000 68:02 12190041                       /lib64/libc-2.5.so
3799353000-3799354000 rw-p 00153000 68:02 12190041                       /lib64/libc-2.5.so
3799354000-3799359000 rw-p 00000000 00:00 0
3799800000-3799802000 r-xp 00000000 68:02 12190043                       /lib64/libdl-2.5.so
3799802000-3799a02000 ---p 00002000 68:02 12190043                       /lib64/libdl-2.5.so
3799a02000-3799a03000 r--p 00002000 68:02 12190043                       /lib64/libdl-2.5.so
3799a03000-3799a04000 rw-p 00003000 68:02 12190043                       /lib64/libdl-2.5.so
37a7200000-37a720d000 r-xp 00000000 68:02 12190065                       /lib64/libgcc_s-4.1.2-20080825.so.1
37a720d000-37a740d000 ---p 0000d000 68:02 12190065                       /lib64/libgcc_s-4.1.2-20080825.so.1
37a740d000-37a740e000 rw-p 0000d000 68:02 12190065                       /lib64/libgcc_s-4.1.2-20080825.so.1
37abe00000-37abe4e000 r-xp 00000000 68:02 3366057                        /usr/lib64/libncurses.so.5.5
37abe4e000-37ac04e000 ---p 0004e000 68:02 3366057                        /usr/lib64/libncurses.so.5.5
37ac04e000-37ac05c000 rw-p 0004e000 68:02 3366057                        /usr/lib64/libncurses.so.5.5
37ac05c000-37ac05d000 rw-p 00000000 00:00 0
7f572595f000-7f5725961000 rw-p 00000000 00:00 0
7f572597c000-7f572597e000 rw-p 00000000 00:00 0
7fff43d39000-7fff43d5a000 rw-p 00000000 00:00 0                          [stack]
7fff43dff000-7fff43e00000 r-xp 00000000 00:00 0                          [vdso]
                                                                                                                                                                                                                                  ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
--最终我确定问题column宽度如果大于等于267问题出现.等于266显示正常。

# stty -a
speed 38400 baud; rows 55; columns 267; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

--顺便看了以下bvi,可以执行set columns=16,或者set cm=16 ,相当于设置80列宽终端.
--man bvi
--columns    cm=16    on an 80 character wide terminal

--set cm=16
$ bvi /tmp/a.ora
00000000  62 6F 6F 6B 2E 5F 5F 64 62 5F 63 61 63 68 65 5F book.__db_cache_
~~~~~~~~~~
00000010  73 69 7A 65 3D 34 33 36 32 30 37 36 31 36 0A 62 size=436207616.b
00000020  6F 6F 6B 2E 5F 5F 6A 61 76 61 5F 70 6F 6F 6C 5F ook.__java_pool_
00000030  73 69 7A 65 3D 34 31 39 34 33 30 34 0A 62 6F 6F size=4194304.boo

--可以看出这样显示74个字符。~线下的字符占10,3*16+16=64,正好74个字符一行。
--不知道是否开头10个字符不算,定义显示的宽度266-10=256,超过这个限制就会出问题。
--不过我在其它版本centos 6.2,redhat 4.3上测试没有问题。估计问题出在oracle 5.9的ncurses上。

# rpm -qif /usr/lib64/libncurses.so.5.5
Name        : ncurses                      Relocations: (not relocatable)
Version     : 5.5                               Vendor: Oracle USA
Release     : 24.20060715                   Build Date: Wed 06 Jun 2007 07:38:52 PM CST
Install Date: Fri 29 Aug 2014 09:26:45 PM CST      Build Host: ca-build14
Group       : System Environment/Libraries   Source RPM: ncurses-5.5-24.20060715.src.rpm
Size        : 3022251                          License: distributable
Signature   : DSA/SHA1, Fri 08 Jun 2007 08:17:31 AM CST, Key ID 66ced3de1e5e0159
URL         : http://invisible-island.net/ncurses/ncurses.html
Summary     : A terminal handling library
Description :
The curses library routines are a terminal-independent method of
updating character screens with reasonable optimization.  The ncurses
(new curses) library is a freely distributable replacement for the
discontinued 4.4 BSD classic curses library.

# ls -l  /usr/lib64/libncurses.so.5.5
-rwxr-xr-x 1 root root 380336 2007-06-06 19:38:41 /usr/lib64/libncurses.so.5.5

--顺便看了centos 6.2版本的情况:
#  ls -l /usr/lib64/libncurses.so
lrwxrwxrwx. 1 root root 27 2012-07-03 12:15:32 /usr/lib64/libncurses.so -> ../../lib64/libncurses.so.5

#  rpm -qif /lib64/libncurses.so.5.7
Name        : ncurses-libs                 Relocations: (not relocatable)
Version     : 5.7                               Vendor: CentOS
Release     : 3.20090208.el6                Build Date: Wed 18 Aug 2010 11:42:34 PM CST
Install Date: Tue 03 Jul 2012 12:11:01 PM CST      Build Host: c6b3.bsys.dev.centos.org
Group       : System Environment/Libraries   Source RPM: ncurses-5.7-3.20090208.el6.src.rpm
Size        : 760448                           License: MIT
Signature   : RSA/8, Sun 03 Jul 2011 12:47:02 PM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://invisible-island.net/ncurses/ncurses.html
Summary     : Ncurses libraries
Description :
The curses library routines are a terminal-independent method of
updating character screens with reasonable optimization.  The ncurses
(new curses) library is a freely distributable replacement for the
discontinued 4.4 BSD classic curses library.

This package contains the ncurses libraries.

--知道以上情况,规避这个问题很简单,不要设置太宽就ok了。
--补充1点小常识:
--如何看当前的窗口显示大小:

# echo $LINES $COLUMNS
55 177

在vim下:
<ESC>
:set window columns