GHSA-rxhx-9fj6-6h2m: Enum map Enum_map Macro Can Cause UB Vulnerability

HIGH
Published
Advisory Summary

GHSA-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

CVE Identifier N/A
GHSA Identifier GHSA-rxhx-9fj6-6h2m
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification General Security Weakness
Affected Product Enum map
Package Ecosystem crates.io
Published Date
Last Updated

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.

enum-map fixed: 2.0.2
Upgrade enum-map to 2.0.2
Verify Direct and Transitive Dependencies

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

Affected versions of this crate did not properly check the length of an enum when using `enum_map!` macro, trusting user-provided length. When 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. This problem can only occur with a manual implementation of the Enum trait, it will never occur for enums that use `#[derive(Enum)]`. Example code that triggers this vulnerability looks like this: ```rust enum E { A, B, C, } impl Enum for E { const LENGTH: usize = 2; fn from_usize(value: usize) -> E { match value { 0 => E::A, 1 => E::B, 2 => E::C, _ => unimplemented!(), } } fn into_usize(self) -> usize { self as usize } } impl<V> EnumArray<V> for E { type Array = [V; 3]; } let _map: EnumMap<E, String> = enum_map! { _ => "Hello, world!".into() }; ``` The 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.

GHSA-rxhx-9fj6-6h2m Affected Enum map Versions

1 component(s)
Fixed Versions:
2.0.2
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?
GHSA-rxhx-9fj6-6h2m is a security vulnerability in Enum map involving enum_map macro can cause UB when `Enum` trait is incorrectly implemented under General Security Weakness.
Which Enum map versions are affected?
Affected versions include releases prior to 2.0.2 across affected packages: enum-map.
What version fixes GHSA-rxhx-9fj6-6h2m?
Upgrading to 2.0.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is enum-map affected?
Yes, enum-map is affected in releases prior to 2.0.2. Upgrade your dependency to 2.0.2 or later.
What CWE is associated with GHSA-rxhx-9fj6-6h2m?
GHSA-rxhx-9fj6-6h2m is classified under General Security Weakness.
How can I check crates.io dependencies for GHSA-rxhx-9fj6-6h2m?
Run the dependency tree command: 'inspect dependencies for enum-map'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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
  }
}