Bug 224869 - Python os.getenv calls should handle the env var being undefined
Summary: Python os.getenv calls should handle the env var being undefined
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sam Sneddon [:gsnedders]
URL:
Keywords: InRadar
Depends on:
Blocks: 224640
  Show dependency treegraph
 
Reported: 2021-04-21 07:46 PDT by Sam Sneddon [:gsnedders]
Modified: 2021-04-21 10:58 PDT (History)
4 users (show)

See Also:


Attachments
Calls to os.getenv (4.22 KB, text/plain)
2021-04-21 07:46 PDT, Sam Sneddon [:gsnedders]
no flags Details
Patch (3.26 KB, patch)
2021-04-21 07:56 PDT, Sam Sneddon [:gsnedders]
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Sneddon [:gsnedders] 2021-04-21 07:46:24 PDT
Created attachment 426681 [details]
Calls to os.getenv

See getenv.txt for a list.

The single-arg variant of os.getenv returns None when the environment variable is undefined. This can cause issues.

Note that this technically isn't blocking 224640, but per https://tox.readthedocs.io/en/latest/config.html#conf-passenv only a limited set of environment variables are passed through by default, and it would be good to avoid relying on anything else being defined by default.

Ignoring those in CISupport (which is also lower priority given we control the configuration in which it is run), having audited all of them, two calls are problematic when None is returned:

Tools/Scripts/webkitpy/common/checkout/scm/svn.py
56:    def has_authorization_for_realm(self, realm, home_directory=os.getenv("HOME")):

Tools/Scripts/webkitpy/common/system/executive.py
357:        command = ["killall", "-TERM", "-u", os.getenv("USER"), process_name]
Comment 1 Radar WebKit Bug Importer 2021-04-21 07:46:32 PDT
<rdar://problem/76958611>
Comment 2 Sam Sneddon [:gsnedders] 2021-04-21 07:56:18 PDT
Created attachment 426686 [details]
Patch
Comment 3 EWS 2021-04-21 10:58:53 PDT
Committed r276374 (236851@main): <https://commits.webkit.org/236851@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 426686 [details].