# CVE-2021-21401: Invalid free() call in Nanopb

- Severity: High 7.1 (CVSS:3.1, scored by GitHub_M) `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L`
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Likelihood of exploitation in the next 30 days (EPSS): 1.81%, higher than 79% of CVEs (2026-12-01)
- Public exploit code or proof of concept: 2 links below, marked "exploit"
- Published: 2021-03-23T17:45:19.000Z
- Modified: 2026-07-08T06:28:07.042Z
- Also known as: GHSA-7mv5-5mxh-qg88, PYSEC-2021-432
- Weaknesses: CWE-763
- Assigned by: GitHub_M

## Description

Nanopb is a small code-size Protocol Buffers implementation in ansi C. In Nanopb before versions 0.3.9.8 and 0.4.5, decoding a specifically formed message can cause invalid `free()` or `realloc()` calls if the message type contains an `oneof` field, and the `oneof` directly contains both a pointer field and a non-pointer field. If the message data first contains the non-pointer field and then the pointer field, the data of the non-pointer field is incorrectly treated as if it was a pointer value. Such message data rarely occurs in normal messages, but it is a concern when untrusted data is parsed. This has been fixed in versions 0.3.9.8 and 0.4.5. See referenced GitHub Security Advisory for more information including workarounds.

(As written by CVE List.)

## Affected

- nanopb nanopb: >= 0.3.2, <= 0.3.9.7; >= 0.4.0, <= 0.4.4
- nanopb (PyPI): from 0.3.2 before 0.3.9.8; from 0.4.0 before 0.4.5; before e2f0ccf939d9f82931d085acb6df8e9a182a4261; before 0.3.9.8
- nanopb_project nanopb: before 0.3.9.8; from 0.4.0 before 0.4.5

## Every score

- GitHub_M: CVSS:3.1 7.1 High `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L`
- GitHub: CVSS:3.1 7.1 High `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L`
- GitHub: CVSS:4.0 High `CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:H/VA:L/SC:N/SI:N/SA:N`
- NVD: CVSS:3.1 7.1 High `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L`
- NVD: CVSS:2.0 5.5 Medium `AV:N/AC:L/Au:S/C:N/I:P/A:P`

## References

- <https://github.com/nanopb/nanopb/security/advisories/GHSA-7mv5-5mxh-qg88> (exploit, advisory, patch, third-party-advisory, web)
- <https://github.com/nanopb/nanopb/issues/647> (exploit, issue-tracking, report, third-party-advisory, web)
- <https://github.com/nanopb/nanopb/commit/e2f0ccf939d9f82931d085acb6df8e9a182a4261> (fix, patch, third-party-advisory, web)
- <https://github.com/nanopb/nanopb/blob/c9124132a604047d0ef97a09c0e99cd9bed2c818/CHANGELOG.txt#L1> (release-notes, third-party-advisory, web)
- <https://nvd.nist.gov/vuln/detail/CVE-2021-21401> (advisory)
- <https://github.com/nanopb/nanopb/commit/4a375a560651a86726e5283be85a9231fd0efe9c> (web)
- <https://github.com/nanopb/nanopb> (package)
- <https://github.com/pypa/advisory-database/tree/main/vulns/nanopb/PYSEC-2021-432.yaml> (web)

## Sources

- CVE List: [CVE-2021-21401](https://www.cve.org/CVERecord?id=CVE-2021-21401), CVE Terms of Use, modified 2024-08-03
- GitHub Advisory Database: [GHSA-7mv5-5mxh-qg88](https://github.com/advisories/GHSA-7mv5-5mxh-qg88), CC-BY-4.0, modified 2026-07-08
- NVD: [CVE-2021-21401](https://nvd.nist.gov/vuln/detail/CVE-2021-21401), Public domain, modified 2026-06-17
- PyPA Advisory Database: [PYSEC-2021-432](https://osv.dev/vulnerability/PYSEC-2021-432), CC-BY-4.0, modified 2023-11-08

---

Page: https://cve.day/CVE-2021-21401 · Whole record: https://cve.day/CVE-2021-21401.json · Rebuilt by cve.day 2026-11-25T22:58:00.396Z
