HomeClusterLabs Projects

Refactor: remoted: Clean up load_env_vars()
cfbf4a43c25bUnpublished

Unpublished Commit ยท Learn More

Not On Permanent Ref: This commit is not an ancestor of any permanent ref.
This commit no longer exists in the repository. It may have been part of a branch which was deleted.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

Event Timeline

Commit No Longer Exists

This commit no longer exists in the repository.