fix(directory): read recursive flag as mrb_bool to prevent unintended recursive delete - #30
Open
ratazzi wants to merge 1 commit into
Open
fix(directory): read recursive flag as mrb_bool to prevent unintended recursive delete#30ratazzi wants to merge 1 commit into
ratazzi wants to merge 1 commit into
Conversation
… recursive delete
mrb_get_args format `b` writes a single mrb_bool (u8), but recursive_val
was declared as mrb_value (8 bytes, undefined). mrb_test() then read the
7 uninitialized high bytes, so the flag evaluated as true regardless of
what the Ruby DSL passed. A plain
directory "/some/dir" do
action :delete
end
(recursive defaults to false) could therefore recursively delete the
whole subtree instead of failing on a non-empty directory -- silent
data loss.
Declare the variable as mrb_bool and compare against zero, matching the
existing pattern in remote_file.zig. Swept the repo for other `b`
format specifiers paired with mrb_value: this was the only one.
Verified end to end: non-recursive delete of a non-empty directory now
fails with DirNotEmpty and leaves the tree intact; recursive true still
deletes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
mrb_get_argsformatbwrites a singlemrb_bool(u8), butrecursive_valwas declared asmrb_value(8 bytes,undefined-initialized).mrb_test()then read the 7 uninitialized high bytes, so the flag evaluated as true regardless of what the Ruby DSL passed.A plain
(
recursivedefaults to false) could therefore recursively delete the whole subtree instead of failing on a non-empty directory — silent data loss.This is the same
b-format pitfall previously fixed inmacos_dock.zig; this call site was missed.Fix
Declare the variable as
mruby.mrb_booland compare against zero, matching the existing pattern inremote_file.zig. Swept the repo for otherbformat specifiers paired withmrb_value— this was the only remaining one.Testing
Verified end to end with the built binary:
action :deleteon a non-empty directory now fails withDirNotEmptyand leaves the tree intact (previously deleted it).recursive truestill deletes the tree.zig build testpasses.