-
Notifications
You must be signed in to change notification settings - Fork 17
Add runtime check for trimmed path #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Package check provides utilities to inspect properties of the running Go | ||
| // binary, with a focus on detecting whether certain build-time flags were used | ||
| // during compilation. | ||
| // | ||
| // For example, using -trimpath can remove absolute file paths from the compiled | ||
| // executable, which affects stack traces and error reporting. This package helps | ||
| // detect that condition at runtime, which can be useful for debugging, logging, | ||
| // or reproducibility checks that otherwise can result in chain halt. | ||
| package check | ||
|
|
||
| import ( | ||
| "runtime" | ||
| "strings" | ||
| ) | ||
|
|
||
| // RuntimePathTrimmed reports whether the Go binary was likely built with | ||
| // the `-trimpath` flag by inspecting the file path of the current call stack. | ||
| // | ||
| // It checks if the file path of the caller frame contains the original module | ||
| // path ("github.com/CosmWasm/wasmd"). If the path contains this prefix, it | ||
| // likely means that `-trimpath` was used to remove or rewrite file system paths | ||
| // in the compiled executable. | ||
| // | ||
| // Note that building with `-trimpath` can remove absolute paths from stack | ||
| // traces, which may affect reproducibility of error reporting. | ||
| // | ||
| // Returns: | ||
| // - trimmed: true if the file path indicates that the module path was trimmed. | ||
| // - ok: true if runtime caller information could be retrieved successfully. | ||
| func RuntimePathTrimmed() (trimmed, ok bool) { | ||
| switch _, file, _, success := runtime.Caller(0); { | ||
| case !success: | ||
| return false, false | ||
| default: | ||
| const modulePathPrefix = "github.com/CosmWasm/wasmd" | ||
| return strings.HasPrefix(file, modulePathPrefix), true | ||
masih marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Oops, something went wrong.
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.
Check notice
Code scanning / CodeQL
Sensitive package import Note