HomeClusterLabs Projects

Refactor: remoted: Clean up load_env_vars()
6ec960ae2cafUnpublished

Unpublished Commit ยท Learn More

Not On Permanent Ref: This commit is not an ancestor of any permanent ref.
This commit has been deleted in the repository: it is no longer reachable from any branch, tag, or ref.

Description

Refactor: remoted: Clean up load_env_vars()

This makes two Coverity false positives (tainted name and value passed
to setenv()) go away. It also makes the function's logic easier to
follow.

We now use getline() instead of fgets(). Instead of reading into a
fixed-size buffer, getline() allocates a buffer large enough to hold the
line, and it calls realloc() as needed. This is not an execution path
where performance is critical enough for this to matter.

getline() also returns the number of characters read, so that if there
is a '\0' character within a line, the caller can tell that the end of
line has not yet been reached. This doesn't seem to matter for our use
case, since we don't want to allow null bytes inside a name or value.

We also make liberal use of continue statements to avoid nesting where
possible, and this allows us to get rid of the places where we set value
to NULL.

This will be painful to review, so sorry in advance.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>

Details

Provenance
nrwahl2Authored on Mar 3 2025, 3:20 AM
Parents
rP182c2168226f: Refactor: remoted: Remove unnecessary nesting in load_env_vars()
Branches
Unknown
Tags
Unknown

Event Timeline