Skip to content

mtd.c: Check for non-directory components in mkdir_p()#146

Merged
ac000 merged 1 commit intomasterfrom
mkdir_p
Sep 15, 2025
Merged

mtd.c: Check for non-directory components in mkdir_p()#146
ac000 merged 1 commit intomasterfrom
mkdir_p

Conversation

@ac000
Copy link
Copy Markdown
Owner

@ac000 ac000 commented Sep 15, 2025

Check the result of the fstatat(2) to see if we got a non-directory path component.

This would really only be a problem if the last component wasn't a directory as otherwise the mkdirat(2) will catch it.

Check the result of the fstatat(2) to see if we got a non-directory path
component.

This would really only be a problem if the *last* component wasn't a
directory as otherwise the mkdirat(2) will catch it.

Signed-off-by: Andrew Clayton <ac@sigsegv.uk>
@ac000 ac000 requested a review from Copilot September 15, 2025 22:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a check to ensure path components are directories when creating directory hierarchies. This prevents the mkdir_p() function from attempting to create directories when a non-directory file exists in the path.

  • Validates that existing path components are directories using S_ISDIR() macro
  • Sets appropriate error code (ENOTDIR) and exits early when encountering non-directory components
  • Improves error handling for edge cases in directory creation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ac000 ac000 merged commit 4a05dc0 into master Sep 15, 2025
10 checks passed
@ac000 ac000 deleted the mkdir_p branch September 15, 2025 22:52
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.

2 participants