# GHSA-pfr9-2p92-qrhq: Heap Buffer overflow using c_chars_to_str function

> A heap buffer overflow in the DBN library allows attackers to read sensitive memory or cause crashes via malformed input.

- **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:** 7 Oct 2024
- **Also known as:** RUSTSEC-2024-0377

## What is GHSA-pfr9-2p92-qrhq?

GHSA-pfr9-2p92-qrhq is a memory corruption vulnerability in dbn, published on 7 Oct 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

The `heap-buffer-overflow` is triggered in the `strlen()` function when handling the `c_chars_to_str` function in the dbn crate. This vulnerability occurs because the `CStr::from_ptr()` function in Rust assumes that the provided C string is null-terminated. However, there is no guarantee that the input chars array passed to the c_chars_to_str function is properly null-terminated.

If the chars array does not contain a null byte (\0), strlen() will continue to read beyond the bounds of the buffer in search of a null terminator. This results in an out-of-bounds memory read and can lead to a heap-buffer-overflow, potentially causing memory corruption or exposing sensitive information.

## Which versions are affected by GHSA-pfr9-2p92-qrhq?

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


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

## How do I fix GHSA-pfr9-2p92-qrhq?

Upgrade dbn to a fixed version for your release line: 0.22.1 or 0.22.1-0.

## Is GHSA-pfr9-2p92-qrhq being exploited?

There is no known exploitation of GHSA-pfr9-2p92-qrhq in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-pfr9-2p92-qrhq and fix it if it is affected.

What it is: GHSA-pfr9-2p92-qrhq is a memory corruption vulnerability in dbn, published on 7 Oct 2024. 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-pfr9-2p92-qrhq in the wild and no public exploit code.

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

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-pfr9-2p92-qrhq/ (Markdown: https://insights.sbomify.com/GHSA-pfr9-2p92-qrhq/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-pfr9-2p92-qrhq

---
From sbomify Insights: https://insights.sbomify.com/GHSA-pfr9-2p92-qrhq/
Summaries are generated and may contain mistakes; the official description above is the record.
