Every CVE Search/ Get API key

CVE-2021-21401

Invalid free() call in Nanopb

7.1 HighPublic exploitFix available

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.

Attack profile

How easy it is to exploit

Attack vector
Network
Complexity
Low
Privileges needed
Low
User interaction
None

What an attacker can affect

Confidentiality
None
Integrity
High
Availability
Low

Exploit likelihood

1.81%Up 0.8 points since Apr 14, 2021
90%50%10%1%

What each source reports

CVE List Score used 7.1

Invalid free() call in Nanopb

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.

Record
CVE-2021-21401
CVSS 3.1
7.1 HighCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L
Weakness
CWE-763
Updated
2026-11-02
EUVDEUVD-2021-0139 7.1

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.

Record
EUVD-2021-0139
CVSS 3.1
7.1 HighCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L
Updated
2026-11-03
GitHub AdvisoriesGHSA-7mv5-5mxh-qg88 7.1

nanopb vulnerable to invalid free() call with oneofs and PB_ENABLE_MALLOC

Impact

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.

Patches

Preliminary patch is available on git for 0.4.x and 0.3.x branches. The fix will be released in versions 0.3.9.8 and 0.4.5 once testing has been completed.

Workarounds

Following workarounds are available:

  • 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.
  • 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.
  • 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.

References

Bug report: https://github.com/nanopb/nanopb/issues/647

For more information

If you have any questions or comments about this advisory, comment on the bug report linked above.

Record
GHSA-7mv5-5mxh-qg88
CVSS 4.0
7.1 HighCVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:H/VA:L/SC:N/SI:N/SA:N
CVSS 3.1
7.1 HighCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L
Weakness
CWE-763
Updated
2026-11-02
NVD 7.1

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.

Record
CVE-2021-21401
CVSS 3.1
7.1 HighCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L
CVSS 2.0
5.5 MediumAV:N/AC:L/Au:S/C:N/I:P/A:P
Weakness
CWE-763
Updated
2026-11-02
OSV 7.1

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.

Record
CVE-2021-21401
CVSS 3.1
7.1 HighCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L
Updated
2026-11-02
OSVDEBIAN-CVE-2021-21401 7.1

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.

Record
DEBIAN-CVE-2021-21401
CVSS 3.1
7.1 HighCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L
Updated
2026-11-02
Show 5 moreShow less
OSVGHSA-7mv5-5mxh-qg88 7.1

nanopb vulnerable to invalid free() call with oneofs and PB_ENABLE_MALLOC

Impact

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.

Patches

Preliminary patch is available on git for 0.4.x and 0.3.x branches. The fix will be released in versions 0.3.9.8 and 0.4.5 once testing has been completed.

Workarounds

Following workarounds are available:

  • 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.
  • 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.
  • 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.

References

Bug report: https://github.com/nanopb/nanopb/issues/647

For more information

If you have any questions or comments about this advisory, comment on the bug report linked above.

Record
GHSA-7mv5-5mxh-qg88
CVSS 4.0
7.1 HighCVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:H/VA:L/SC:N/SI:N/SA:N
CVSS 3.1
7.1 HighCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L
Weakness
CWE-763
Updated
2026-11-02
OSVUBUNTU-CVE-2021-21401 7.1

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.

Record
UBUNTU-CVE-2021-21401
CVSS 3.1
7.1 HighCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L
Updated
2026-11-02
OSVopenSUSE-SU-2024:11074-1 No score

libprotobuf-nanopb0-0.4.5-1.3 on GA media

These are all security issues fixed in the libprotobuf-nanopb0-0.4.5-1.3 package on the GA media of openSUSE Tumbleweed.

Record
openSUSE-SU-2024:11074-1
Updated
2026-11-02
OSVPYSEC-2021-432 No score

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.

Record
PYSEC-2021-432
Updated
2026-11-02
OSVUSN-6121-1 No score

nanopb vulnerabilities

It was discovered that Nanopb incorrectly handled certain decode messages. An attacker could possibly use this cause a denial of service or expose sensitive information. (CVE-2020-26243)

It was discovered that Nanopb incorrectly handled certain decode messages. An attacker could possibly use this issue to cause a denial of service or execute arbitrary code. (CVE-2021-21401)

Record
USN-6121-1
Updated
2026-11-02

Affected products

Affected packages

Affected packages
PackageAffectedFixed
nanopb
PyPI
0.3.2 up to 0.3.9.8
0.3.9.8
nanopb
PyPI
0.4.0 up to 0.4.5
0.4.5
nanopb
Debian:12
before 0.4.4-2
0.4.4-2
nanopb
Debian:13
before 0.4.4-2
0.4.4-2
nanopb
Debian:14
before 0.4.4-2
0.4.4-2
nanopb
PyPI
0.3.2 up to 0.3.9.8, plus listed versions
0.3.9.4.post30.3.9.50.3.9.60.3.9.7
0.3.9.8
nanopb
PyPI
0.4.0 up to 0.4.5, plus listed versions
0.4.10.4.1.dev10030.4.1.dev10070.4.1.dev10120.4.1.dev1013
Show 45 moreShow less
0.4.1.dev10170.4.1.dev10360.4.1.dev9590.4.1.dev9610.4.1.dev9620.4.1.dev9640.4.1.dev9710.4.1.dev9780.4.1.dev9800.4.1.dev9850.4.1.dev9870.4.1.dev9880.4.1.dev9960.4.1.dev9970.4.20.4.2.dev10410.4.2.dev10430.4.2.dev10440.4.2.dev10450.4.2.dev10480.4.2.dev10500.4.2.dev10530.4.2.dev10540.4.2.dev10550.4.2.dev10580.4.2.dev10590.4.2.dev10630.4.2.dev10660.4.2.dev10700.4.2.dev10710.4.2.dev10720.4.2.dev10760.4.2.dev10880.4.2.dev10910.4.30.4.3.dev11280.4.3.dev11310.4.3.dev11320.4.3.dev11330.4.3.dev11370.4.3.dev11500.4.3.dev11640.4.3.dev11720.4.3.dev11750.4.3.dev1177
0.4.5
nanopb
PyPI
before 0.3.9.8, 0.4.0 up to 0.4.5, plus listed versions
0.3.9.4.post30.3.9.50.3.9.60.3.9.70.4.1
Show 45 moreShow less
0.4.1.dev10030.4.1.dev10070.4.1.dev10120.4.1.dev10130.4.1.dev10170.4.1.dev10360.4.1.dev9590.4.1.dev9610.4.1.dev9620.4.1.dev9640.4.1.dev9710.4.1.dev9780.4.1.dev9800.4.1.dev9850.4.1.dev9870.4.1.dev9880.4.1.dev9960.4.1.dev9970.4.20.4.2.dev10410.4.2.dev10430.4.2.dev10440.4.2.dev10450.4.2.dev10480.4.2.dev10500.4.2.dev10530.4.2.dev10540.4.2.dev10550.4.2.dev10580.4.2.dev10590.4.2.dev10630.4.2.dev10660.4.2.dev10700.4.2.dev10710.4.2.dev10720.4.2.dev10760.4.2.dev10880.4.2.dev10910.4.30.4.3.dev11280.4.3.dev11310.4.3.dev11320.4.3.dev11330.4.3.dev11370.4.3.dev1150
0.3.9.80.4.5
nanopb
Ubuntu:Pro:20.04:LTS
before 0.4.1-1ubuntu0.1~esm1, plus listed versions
0.4.1-1
0.4.1-1ubuntu0.1~esm1
nanopb
Ubuntu:Pro:20.04:LTS
From an advisory covering 2 CVEs
before 0.4.1-1ubuntu0.1~esm1, plus listed versions
0.4.1-1
0.4.1-1ubuntu0.1~esm1
nanopb
openSUSE:Tumbleweed
From an advisory covering 3 CVEs
before 0.4.5-1.3
0.4.5-1.3

Public exploits

Links only. Every CVE stores no exploit code.

Public exploits
SourceLinkDate
PoC in GitHubuthrasri/CVE-2021-21401_nanopb-c_AOSP10_R332024-11-05

History

History
RecordedChangedSources
affected, facts
aliasesEUVD
first indexedCVE List, GitHub Advisories, NVD, OSV, PoC in GitHub

Dates are when Every CVE recorded each change. Upstream dates may differ.

In short

CVE-2021-21401 is a high vulnerability (CVSS 7.1) in Nanopb, published March 23, 2021. Public exploit code exists. EPSS puts the chance of exploitation in the next 30 days at 1.81%, the 78th percentile. Fixed in nanopb 0.3.9.8.

References

Show 11 moreShow less
This page doesn't list everything

Left out here: 36 versions. The JSON record has them.

MoveEnter Open