GHSA-rxhx-9fj6-6h2m: Enum map Enum_map Macro Can Cause UB Vulnerability
HIGHGHSA-rxhx-9fj6-6h2m is a HIGH enum_map macro can cause ub vulnerability (General Security Weakness) affecting Enum map libraries in the crates.io ecosystem. The issue involves enum_map macro can cause ub when `enum` trait is incorrectly implemented. Remediation is available by upgrading affected packages to version 2.0.2.
GHSA-rxhx-9fj6-6h2m at a Glance
How to Fix GHSA-rxhx-9fj6-6h2m
To remediate this vulnerability, upgrade all affected Enum map dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade enum-map to 2.0.2
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for enum-map
How to Check if You Are Affected
To determine whether your application is affected by GHSA-rxhx-9fj6-6h2m, inspect your project dependencies for Enum map:
inspect dependencies for enum-map
Analyze the terminal output to locate any version of Enum map in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.2), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under General Security Weakness. In Enum map, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
GHSA-rxhx-9fj6-6h2m Affected Enum map Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
enum-map
|
crates.io |
≥ 2.0.0-2
< 2.0.2
|
2.0.2
|
References
Frequently Asked Questions
What is GHSA-rxhx-9fj6-6h2m?
Which Enum map versions are affected?
What version fixes GHSA-rxhx-9fj6-6h2m?
Is enum-map affected?
What CWE is associated with GHSA-rxhx-9fj6-6h2m?
How can I check crates.io dependencies for GHSA-rxhx-9fj6-6h2m?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-rxhx-9fj6-6h2m",
"modified" : "2022-06-20T18:15:47Z",
"published" : "2022-06-16T23:53:32Z",
"aliases" : [ ],
"summary" : "enum_map macro can cause UB when `Enum` trait is incorrectly implemented",
"details" : "Affected versions of this crate did not properly check the length of an enum when using `enum_map!` macro, trusting user-provided length.\n\nWhen the `LENGTH` in the `Enum` trait does not match the array length in the `EnumArray` trait, this can result in the initialization of the enum map with uninitialized types, which in turn can allow an attacker to execute arbitrary code.\n\nThis problem can only occur with a manual implementation of the Enum trait, it will never occur for enums that use `#[derive(Enum)]`.\n\nExample code that triggers this vulnerability looks like this:\n\n```rust\nenum E {\n A,\n B,\n C,\n}\n\nimpl Enum for E {\n const LENGTH: usize = 2;\n\n fn from_usize(value: usize) -> E {\n match value {\n 0 => E::A,\n 1 => E::B,\n 2 => E::C,\n _ => unimplemented!(),\n }\n }\n\n fn into_usize(self) -> usize {\n self as usize\n }\n}\n\nimpl<V> EnumArray<V> for E {\n type Array = [V; 3];\n}\n\nlet _map: EnumMap<E, String> = enum_map! { _ => \"Hello, world!\".into() };\n```\n\nThe flaw was corrected in commit [b824e23](https://github.com/xfix/enum-map/commit/b824e232f2fb47837740070096ac253df8e80dfc) by putting `LENGTH` property on sealed trait for macro to read.\n",
"severity" : [ ],
"affected" : [ {
"package" : {
"ecosystem" : "crates.io",
"name" : "enum-map"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.0.0-2"
}, {
"fixed" : "2.0.2"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/xfix/enum-map/commit/b824e232f2fb47837740070096ac253df8e80dfc"
}, {
"type" : "WEB",
"url" : "https://github.com/rustsec/advisory-db/blob/main/crates/enum-map/RUSTSEC-2022-0010.md"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/xfix/enum-map"
}, {
"type" : "WEB",
"url" : "https://github.com/xfix/enum-map/blob/master/CHANGELOG.md#version-202"
}, {
"type" : "WEB",
"url" : "https://gitlab.com/KonradBorowski/enum-map/-/blob/master/CHANGELOG.md#version-202"
}, {
"type" : "WEB",
"url" : "https://rustsec.org/advisories/RUSTSEC-2022-0010.html"
} ],
"database_specific" : {
"cwe_ids" : [ ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2022-06-16T23:53:32Z",
"nvd_published_at" : null
}
}