{"id":"CVE-2021-21401","aliases":["CVE-2021-21401","GHSA-7mv5-5mxh-qg88","PYSEC-2021-432"],"related":[],"kind":"vulnerability","state":"published","title":"Invalid free() call in Nanopb","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"### Impact\nDecoding 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.\n\n### Patches\nPreliminary patch is available on git for [0.4.x](https://github.com/nanopb/nanopb/commit/e2f0ccf939d9f82931d085acb6df8e9a182a4261) and [0.3.x](https://github.com/nanopb/nanopb/commit/4a375a560651a86726e5283be85a9231fd0efe9c) branches. The fix will be released in versions 0.3.9.8 and 0.4.5 once testing has been completed.\n\n### Workarounds\nFollowing workarounds are available:\n* Set the option `no_unions` for the oneof field. This will generate fields as separate instead of C union, and avoids triggering the problematic code.\n* Set the type of all fields inside the oneof to `FT_POINTER`. This ensures that the data contained inside the `union` is always a valid pointer.\n* Heap implementations that guard against invalid `free()` provide a partial mitigation. Depending on the message type, the pointer value may be attacker controlled and can be used to bypass heap protections.\n\n### References\nBug report: https://github.com/nanopb/nanopb/issues/647\n\n### For more information\nIf you have any questions or comments about this advisory, comment on the bug report linked above.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Nanopb es una implementación de Protocol Buffers de tamaño de código pequeño en ansi C. En Nanopb versiones anteriores a 0.3.9.8 y 0.4.5, la decodificación de un mensaje formado específicamente puede causar llamadas \"free()\" o \"realloc()\" no válidas si el tipo de mensaje contiene un campo \"oneof\", y el \"oneof\" contiene directamente un campo pointer como un campo non-pointer.&#xa0;Si los datos del mensaje contienen primero el campo non-pointer y luego el campo pointer, los datos del campo non-pointer son tratados incorrectamente como si fuera un valor pointer.&#xa0;Estos datos de mensajes raramente ocurren en mensajes normales, pero es una preocupación cuando son analizados datos que no son confiables.&#xa0;Esto ha sido corregido en versiones 0.3.9.8 y 0.4.5.&#xa0;Consulte el Aviso de Seguridad de GitHub al que se hace referencia para obtener más información, incluyendo las soluciones","source":"nvd"}],"published":"2021-03-23T17:45:19.000Z","modified":"2026-07-08T06:28:07.042Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L","score":7.1,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L","score":7.1,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L","score":7.1,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"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","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L","score":7.1,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:L/Au:S/C:N/I:P/A:P","score":5.5,"rating":"MEDIUM"}],"cwes":["CWE-763"],"affected":[{"ranges":[{"version":">= 0.3.2, <= 0.3.9.7","status":"affected"},{"version":">= 0.4.0, <= 0.4.4","status":"affected"}],"vendor":"nanopb","product":"nanopb","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0.3.2","status":"affected","fixed":"0.3.9.8"}],"ecosystem":"PyPI","package":"nanopb","purl":"pkg:pypi/nanopb","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0.4.0","status":"affected","fixed":"0.4.5"}],"ecosystem":"PyPI","package":"nanopb","purl":"pkg:pypi/nanopb","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"0.3.9.8"},{"status":"affected","introduced":"0.4.0","fixed":"0.4.5"}],"vendor":"nanopb_project","product":"nanopb","cpe":"cpe:2.3:a:nanopb_project:nanopb:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"e2f0ccf939d9f82931d085acb6df8e9a182a4261"},{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.3.9.8"},{"type":"ecosystem","introduced":"0.4.0","status":"affected","fixed":"0.4.5"}],"ecosystem":"PyPI","package":"nanopb","purl":"pkg:pypi/nanopb","repo":"https://github.com/nanopb/nanopb","source":"pysec"}],"references":[{"url":"https://github.com/nanopb/nanopb/security/advisories/GHSA-7mv5-5mxh-qg88","tags":["advisory","exploit","patch","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/nanopb/nanopb/issues/647","tags":["exploit","issue-tracking","report","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/nanopb/nanopb/commit/e2f0ccf939d9f82931d085acb6df8e9a182a4261","tags":["fix","patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/nanopb/nanopb/blob/c9124132a604047d0ef97a09c0e99cd9bed2c818/CHANGELOG.txt#L1","tags":["release-notes","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-21401","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/nanopb/nanopb/commit/4a375a560651a86726e5283be85a9231fd0efe9c","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/nanopb/nanopb","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/nanopb/PYSEC-2021-432.yaml","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-21401","url":"https://www.cve.org/CVERecord?id=CVE-2021-21401","licence":"CVE Terms of Use","modified":"2024-08-03T18:09:16.087Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-7mv5-5mxh-qg88","url":"https://github.com/advisories/GHSA-7mv5-5mxh-qg88","licence":"CC-BY-4.0","modified":"2026-07-08T06:28:07.042Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-21401","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-21401","licence":"Public domain","modified":"2026-06-17T03:35:29.647Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2021-432","url":"https://osv.dev/vulnerability/PYSEC-2021-432","licence":"CC-BY-4.0","modified":"2023-11-08T04:04:44.596Z"}],"updatedAt":"2026-11-25T22:58:00.396Z","epss":{"score":0.01811,"percentile":0.79265,"date":"2026-12-01T12:00:22.000Z"}}