# GHSA-c439-chv8-8g2j: `os_socketaddr` invalidly assumes the memory layout of std::net::SocketAddr

> The os_socketaddr crate causes undefined behavior by incorrectly casting Rust socket addresses to C structures, potentially leading to crashes or code execution.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 26 Aug 2022
- **Also known as:** RUSTSEC-2022-0052

## What is GHSA-c439-chv8-8g2j?

GHSA-c439-chv8-8g2j is a memory corruption vulnerability in os_socketaddr, published on 26 Aug 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

The [`os_socketaddr`](https://crates.io/crates/os_socketaddr) crate has assumed `std::net::SocketAddrV4` and `std::net::SocketAddrV6` have the same memory layout as the system C representation `sockaddr`. It has simply casted the pointers to convert the socket addresses to the system representation.

These layout were [changed into idiomatic rust types](https://github.com/rust-lang/rust/pull/78802) in nightly `std`. Starting from rustc 1.64 the affected versions of this crate will have undefined behaviour.

## Which versions are affected by GHSA-c439-chv8-8g2j?

3 open source packages ship an affected version, including os_socketaddr.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `os_socketaddr` | crates.io | All versions | 0.2.2 |
| `os_socketaddr` | crates.io | All versions | 0.2.2 |
| `os_socketaddr` | crates.io | From 0.0.0-0 | 0.2.2 |

## How do I fix GHSA-c439-chv8-8g2j?

Upgrade os_socketaddr to 0.2.2 or later.

## Is GHSA-c439-chv8-8g2j being exploited?

There is no known exploitation of GHSA-c439-chv8-8g2j in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-c439-chv8-8g2j and fix it if it is affected.

What it is: GHSA-c439-chv8-8g2j is a memory corruption vulnerability in os_socketaddr, published on 26 Aug 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-c439-chv8-8g2j in the wild and no public exploit code.

Affected packages and fixed versions:
- os_socketaddr (crates.io): affected all versions; fixed in 0.2.2
- os_socketaddr (crates.io): affected all versions; fixed in 0.2.2
- os_socketaddr (crates.io): affected from 0.0.0-0; fixed in 0.2.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-c439-chv8-8g2j/ (Markdown: https://insights.sbomify.com/GHSA-c439-chv8-8g2j/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-c439-chv8-8g2j

---
From sbomify Insights: https://insights.sbomify.com/GHSA-c439-chv8-8g2j/
Summaries are generated and may contain mistakes; the official description above is the record.
