Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 565868 - app-shells/bash: 'compgen -v' includes variables that are global-set but local-unset
Summary: app-shells/bash: 'compgen -v' includes variables that are global-set but loca...
Status: RESOLVED CANTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-15 23:07 UTC by Michał Górny
Modified: 2022-07-29 08:52 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2015-11-15 23:07:35 UTC
A simple test case:

  TEST=value

  foo() {
    local TEST
    unset TEST # even this doesn't help
    compgen -v | grep TEST
    declare -p TEST
  }
  foo

As you can see, 'compgen -v' lists the variable even though it's unset and unusable in local scope.
Comment 1 kfm 2022-07-29 08:20:53 UTC
This was raised on the bug-bash list in 2017 but Chet is not amenable to the notion of changing this behaviour, and it appears unlikely that he ever will be. See https://www.mail-archive.com/bug-bash@gnu.org/msg19438.html in particular.

Somewhat related is that bash-5.0 added the "localvar_unset" option, which prevents unset from popping the value from an outer scope.

# bash -c 'x=0; f1() { local x=1; f2; x=2; }; f2() { unset x; declare -p x; }; f1; declare -p x'
declare -- x="0"
declare -- x="2"

$ bash -O localvar_unset -c 'x=0; f1() { local x=1; f2; x=2; }; f2() { unset x; declare -p x; }; f1; declare -p x'
declare -- x
declare -- x="0"

I suppose that makes this CANTFIX.
Comment 2 kfm 2022-07-29 08:34:00 UTC
Coincidentally, https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00134.html was posted today.
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-07-29 08:42:43 UTC
(In reply to Kerin Millar from comment #2)
> Coincidentally,
> https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00134.html was posted
> today.

I was wondering if you commented because of this or not :)
Comment 4 kfm 2022-07-29 08:52:48 UTC
(In reply to Sam James from comment #3)
> (In reply to Kerin Millar from comment #2)
> > Coincidentally,
> > https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00134.html was posted
> > today.
> 
> I was wondering if you commented because of this or not :)

Believe it or not, it was entirely coincidental! Notwithstanding, I did just reply in the thread.