Bug 251275

Summary: shells/ksh2020 "complete -F" doesn't work unless the prefix length is exactly 3
Product: Ports & Packages Reporter: Romeo Rajomalaza <endian.sign>
Component: Individual Port(s)Assignee: Cy Schubert <cy>
Status: Closed FIXED    
Severity: Affects Only Me Keywords: patch
Priority: --- Flags: bugzilla: maintainer-feedback? (cy)
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Don't reassign the "len" variable and compute the exact spaces needed none

Description Romeo Rajomalaza 2020-11-20 16:10:56 UTC
Created attachment 219832 [details]
Don't reassign the "len" variable and compute the exact spaces needed

Hi,

The programmable completion of ksh2020 doesn't work as expected unless the prefix length is exactly 3.  The following example illustrates the problem:

$ set -o emacs
$ _foo()
> {
> COMPREPLY=( hello world )
> }
$ complete -F _foo foo
$ foo <tab> # Nothing is displayed.
$ foo hel<tab> # This one works as expected.

The problem is caused by a reassignment of the prefix length.  Moreover, we might overwrite data on the heap if the total length of all completion strings is big enough.  The attached patch fixes the problem.
Comment 1 commit-hook freebsd_committer freebsd_triage 2020-12-02 18:44:22 UTC
A commit references this bug:

Author: cy
Date: Wed Dec  2 18:43:36 UTC 2020
New revision: 556844
URL: https://svnweb.freebsd.org/changeset/ports/556844

Log:
  Don't reassign the "len" variable and compute the exact spaces needed.

  PR:		251275
  Submitted by:	Romeo Rajomalaza <endian.sign _ gmail.com>
  Reported by:	Romeo Rajomalaza <endian.sign _ gmail.com>
  MFH:		2020Q4

Changes:
  head/shells/ksh2020/Makefile
  head/shells/ksh2020/files/patch-src_cmd_ksh93_edit_pcomplete.c
Comment 2 commit-hook freebsd_committer freebsd_triage 2020-12-03 04:23:26 UTC
A commit references this bug:

Author: cy
Date: Thu Dec  3 04:22:52 UTC 2020
New revision: 556884
URL: https://svnweb.freebsd.org/changeset/ports/556884

Log:
  MFH: r556844

  Don't reassign the "len" variable and compute the exact spaces needed.

  PR:		251275
  Submitted by:	Romeo Rajomalaza <endian.sign _ gmail.com>
  Reported by:	Romeo Rajomalaza <endian.sign _ gmail.com>
  Approved by:	ports-secteam (fluffy)

Changes:
_U  branches/2020Q4/
  branches/2020Q4/shells/ksh2020/Makefile
  branches/2020Q4/shells/ksh2020/files/patch-src_cmd_ksh93_edit_pcomplete.c
Comment 3 Cy Schubert freebsd_committer freebsd_triage 2021-03-27 03:11:15 UTC
Committed. Thanks for the patch.