Skip to content

Do not use the path variable in switch_dir() in case of error#534

Merged
millert merged 1 commit intosudo-project:mainfrom
aplopez:unsigned-count
May 4, 2026
Merged

Do not use the path variable in switch_dir() in case of error#534
millert merged 1 commit intosudo-project:mainfrom
aplopez:unsigned-count

Conversation

@aplopez
Copy link
Copy Markdown
Contributor

@aplopez aplopez commented May 4, 2026

In the function switch_dir() the path variable is initialized to NULL.

The read_dir_files() is invoked to assign it a value. When this function finishes with an error (goes to oom or bad), no value is assigned to the parameter *pathsp and SIZE_MAX is returned. SIZE_MAX is the equivalent of -1, but is unsigned, so it is a very high positive value.

Function switch_dir() will check that the result is greater than 0, which will be in case of error because the variable count and the result value are both unsigned, although the equivalent of -1. So we need to check for this particular value explicitly.

Resolves: #533

In the function switch_dir() the path variable is initialized to NULL.

The read_dir_files() is invoked to assign it a value. When this function
finishes with an error (goes to oom or bad), no value is assigned to
the parameter *pathsp and SIZE_MAX is returned. SIZE_MAX is the equivalent
of -1, but is unsigned, so it is a very high positive value.

Function switch_dir() will check that the result is greater than 0, which
will be in case of error because the variable count and the result value
are both unsigned, although the equivalent of -1. So we need to check for
this particular value explicitly.
Copy link
Copy Markdown
Collaborator

@millert millert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@millert millert merged commit a40200a into sudo-project:main May 4, 2026
3 checks passed
@aplopez aplopez deleted the unsigned-count branch May 5, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Function switch_dir() must no use path in case of error

2 participants