Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 772806 - PKGDIR gets evaluated which causes infinite loop
Summary: PKGDIR gets evaluated which causes infinite loop
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on: 766117
Blocks:
  Show dependency tree
 
Reported: 2021-02-25 02:20 UTC by dkjii
Modified: 2021-03-31 20:54 UTC (History)
1 user (show)

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


Attachments
emerge --info (emerge.info,4.25 KB, application/x-info)
2021-02-25 02:30 UTC, dkjii
Details

Note You need to log in before you can comment on or make changes to this bug.
Description dkjii 2021-02-25 02:20:38 UTC
emerge will have an infinite loop with some obscure values of PKGDIR. This might happen with other variables, see below.

Reproducible: Always

Steps to Reproduce:
1. FEATURES='buildpkg' PKGDIR='$(true)' emerge -1 acct-user/man
Actual Results:  
infinite loop - emerge hangs with high CPU%

Expected Results:  
successfully calculates dependencies/emerges OR error about unsupported PKGDIR format

I added a breakpoint and this is the traceback:
Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.8/emerge", line 51, in <module>
    retval = emerge_main()
  File "/usr/lib/python3.8/site-packages/_emerge/main.py", line 1317, in emerge_main
    return run_action(emerge_config)
  File "/usr/lib/python3.8/site-packages/_emerge/actions.py", line 3376, in run_action
    retval = action_build(emerge_config, spinner=spinner)
  File "/usr/lib/python3.8/site-packages/_emerge/actions.py", line 530, in action_build
    not trees[eroot]["bintree"].dbapi.writable:
  File "/usr/lib/python3.8/site-packages/portage/dbapi/bintree.py", line 102, in writable
    return os.access(first_existing(self.bintree.pkgdir), os.W_OK)
  File "/usr/lib/python3.8/site-packages/portage/util/path.py", line 26, in first_existing
    os.lstat(path)

first_existing does infinite loop because it assumes that iter_parents will reach /, but it does not if path == "" as os.path.dirname("") == ""

Apart from the infinite loop, is PKGDIR supposed to evaluate? It's not evaluated with PKGDIR='$(true)' emerge --info, but when it reaches the above tracepoint, it's evaluated to ""
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-02-25 02:27:55 UTC
Portage version? Is this new? (Assume not?)
Comment 2 dkjii 2021-02-25 02:30:01 UTC
Created attachment 688290 [details]
emerge --info

emerge --info, tested on multiple different configs and different profiles
Comment 3 dkjii 2021-02-25 05:40:36 UTC
>Is this new?

I dont know, this came up because of a mistake in a personal script
Comment 4 Larry the Git Cow gentoo-dev 2021-02-25 10:21:06 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=061a895f7b0a310b374dff03af622b11146337d4

commit 061a895f7b0a310b374dff03af622b11146337d4
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2021-02-25 10:14:18 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2021-02-25 10:18:02 +0000

    iter_parents: prevent infinite loop after empty os.path.dirname result
    
    Reported-by: dkjii@cock.li
    Bug: https://bugs.gentoo.org/772806
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 lib/portage/util/path.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)