Skip to content
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

Panics as error-handling #20

Open
code423n4 opened this issue Sep 8, 2021 · 3 comments
Open

Panics as error-handling #20

code423n4 opened this issue Sep 8, 2021 · 3 comments
Labels

Comments

@code423n4
Copy link
Contributor

Handle

nascent

Vulnerability details

[H-04] Panics as error-handling

Severity: High
Likelihood: Medium

The use of .unwrap(), expect(), and assert!() should be limited to tests, compile-time assertions (e.g. consts), and configuration checks. Panicks are at the thread level, so stopping one thread unexpectedly could cause undefined behavior in others. This can become a system-wide vulnerability when the panic can occur from reading the state of a contract due to it affecting all running daemons. Additionally, some of these unwraps, expects and asserts occur based off contract log output. Given how resyncing works, its possible for these panics to persist across process lifetimes (i.e. spin-up, crash, spin-up, crash...) resulting in a patch being required before the bridge returns to an operational state.

Recommendation

Wherever possible, replace instances of unwrap(), expect(), and assert!() with a Result::Err(). Where necessary, change function signatures to return a Result<> and handle error cases at the highest level of execution, even if this means intentionally throwing away a result:

let _res : Result<_, _> = func_that_can_fail();

or, ideally, logging any error condition

if let Err(e) = func_that_canfail() {
    log!("error");
}
@code423n4 code423n4 added 3 (High Risk) bug Something isn't working labels Sep 8, 2021
code423n4 added a commit that referenced this issue Sep 8, 2021
@jkilpatr
Copy link
Collaborator

jkilpatr commented Sep 10, 2021

Without a clear exploit path this is a style issue. Noting that panic halts rust programs is hardly a useful report, building a program with no use of panic will not ensure it works.

@albertchon
Copy link
Collaborator

Yeah this needs a specific example, otherwise it's not relevant

@loudoguno
Copy link

reopening as per judges assessment as "primary issue" on findings sheet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants