https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=279762
Bug ID: 279762
Summary: libedit's cv_prev_word() can read before start of
buffer
Product: Base System
Version: CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: bin
Assignee: [email protected]
Reporter: [email protected]
This code in contrib/libedit/chared.c cv_prev_word():
while (n--) {
...;
test = (*wtest)(*p);
while ((p >= low) && (*wtest)(*p) == test)
p--;
The ">=" can cause p to be decremented even when it is equal to low,
so that the next iteration of the outer loop dereferences an illegal p.
If I run valgrind /bin/sh and type
$ set -o vi
then:
ESC
option-shift-s
option-shift-3
2
b
valgrind says:
Invalid read of size 4
at 0x4873DA1: cv_prev_word (rtm/freebsd/contrib/libedit/chared.c:319)
by 0x489C6D0: vi_prev_word (rtm/freebsd/contrib/libedit/vi.c:189)
by 0x4889747: el_wgets (rtm/freebsd/contrib/libedit/read.c:540)
by 0x4879B3C: el_gets (rtm/freebsd/contrib/libedit/eln.c:75)
by 0x123D6E: preadfd (rtm/freebsd/bin/sh/input.c:138)
by 0x12387A: preadbuffer (rtm/freebsd/bin/sh/input.c:210)
by 0x1326C5: xxreadtoken (rtm/freebsd/bin/sh/parser.c:910)
by 0x12E4FC: readtoken (rtm/freebsd/bin/sh/parser.c:827)
by 0x12E379: parsecmd (rtm/freebsd/bin/sh/parser.c:222)
by 0x129786: cmdloop (rtm/freebsd/bin/sh/main.c:206)
by 0x1295D2: main (rtm/freebsd/bin/sh/main.c:167)
Address 0x552186c is 4 bytes before a block of size 4,096 alloc'd
at 0x4851735: calloc (vg_replace_malloc.c:1599)
by 0x48740AA: ch_init (rtm/freebsd/contrib/libedit/chared.c:399)
by 0x4877714: el_init_internal (rtm/freebsd/contrib/libedit/el.c:107)
by 0x48775B0: el_init_fd (rtm/freebsd/contrib/libedit/el.c:124)
by 0x487754A: el_init (rtm/freebsd/contrib/libedit/el.c:66)
by 0x1215BC: histedit (rtm/freebsd/bin/sh/histedit.c:183)
by 0x12C1ED: optschanged (rtm/freebsd/bin/sh/options.c:130)
by 0x12BEA1: procargs (rtm/freebsd/bin/sh/options.c:121)
by 0x1293EC: main (rtm/freebsd/bin/sh/main.c:131)
FreeBSD stock14 15.0-CURRENT FreeBSD 15.0-CURRENT #22
main-n270479-ecd1d1f1dac4-dirty: Thu May 30 18:42:11 AST 2024
root@stock14:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64
--
You are receiving this mail because:
You are the assignee for the bug.