Skip to content

Conversation

@SeanTUT
Copy link
Contributor

@SeanTUT SeanTUT commented Oct 27, 2025

When std.zig.resolveTargetQuery detects the native OS version, any SemanticVersion contained in the return value would use a stack buffer for the "pre" and "build" fields. This would result in a stale reference being returned from the function. To remedy this, an additional allocator parameter was added to the function.

@SeanTUT
Copy link
Contributor Author

SeanTUT commented Oct 27, 2025

cc @alexrp, as discussed in #25693

@alexrp
Copy link
Member

alexrp commented Oct 27, 2025

Actually, now that I look at this a bit closer... there is indeed a stack UAF bug here, but I think the solution isn't to heap-allocate; rather, I think we should just throw away any non-null values for pre and build in the returned std.SemanticVersion instance.

std.Target in general assumes that versions are of the form major.minor[.patch] (with patch defaulting to 0), and that's also the only format the target triple syntax accepts. So it's actually pretty weird for native target resolution to introduce data beyond that form. I also don't think pre and build would ever be useful for anything in the std.Target context as they are not semantically meaningful per SemVer.

Instead of duplicating the prerelease and build components, we now
ignore them altogether. This is implemented in
Target.Query.parseVersion, which now additionally discards the
prerelease and build components.
@SeanTUT SeanTUT force-pushed the target-resolve-safety-patch branch from 78ed81b to f2f5a20 Compare October 27, 2025 17:19
SeanTUT and others added 3 commits October 27, 2025 13:20
This was removed while implementing the ignoring of prerelease and build
components, but currently it is incorrect to leave out
Now the test ensures that the function returns an error rather than
discarding the components
@alexrp alexrp self-assigned this Oct 28, 2025
Co-authored-by: Alex Rønne Petersen <[email protected]>
@alexrp alexrp merged commit 35e1755 into ziglang:master Oct 28, 2025
7 of 9 checks passed
@alexrp alexrp removed their assignment Oct 28, 2025
TibboddiT pushed a commit to TibboddiT/zig that referenced this pull request Oct 28, 2025
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