Stack-buffer-overflow in sc_asn1_read_tag in opensc

opensc Updated 02 Oct 2025

Summary

29/06/2022
MEDIUM
Yes i
Medium
Not published

OSV-2022-520: Stack-buffer-overflow in sc_asn1_read_tag. Affects opensc versions >= 972d3292eee44e9b4c61769365a3ec651ec18f39, < fa378dadb5ee62c5dc1119639ddae797c166a08f. Fixed in fa378dadb5ee62c5dc1119639ddae797c166a08f. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

OpenSC is an open-source smart card library that provides a set of cryptographic and security functions for interacting with smart cards. It is commonly used in applications that require smart card authentication and secure data storage. The vulnerability in question affects the sc_asn1_read_tag function in OpenSC, which is responsible for reading ASN.1 tags from smart card data. This vulnerability can lead to a stack-buffer-overflow, potentially allowing an attacker to execute arbitrary code or crash the application.

Vulnerability Detail

The vulnerability arises due to a stack-buffer-overflow in the sc_asn1_read_tag function. When processing ASN.1 tags, the function fails to properly validate the length of the tag, leading to a buffer overflow. An attacker can exploit this vulnerability by crafting a malicious smart card data that triggers the overflow. The consequences of this vulnerability can range from remote code execution to denial-of-service attacks, depending on how the application handles the corrupted data. The vulnerability has a medium severity rating.

How To Fix

Minimum fixed version

fa378dadb5ee62c5dc1119639ddae797c166a08f

This is the first release that contains the fix.

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a workaround, developers can implement input validation and bounds checking when processing smart card data. By ensuring that the length of the tag is properly validated before processing, the risk of a buffer overflow can be mitigated. Here is an example of how input validation can be implemented in C:

void process_smart_card_data(const unsigned char* data, size_t length) {
  if (length < MIN_TAG_LENGTH) {
    // Handle error or reject the data
    return;
  }

  // Process the smart card data
}

Conclusion

In conclusion, the stack-buffer-overflow vulnerability in the sc_asn1_read_tag function of the OpenSC library can potentially allow an attacker to execute arbitrary code or crash the application. It is crucial for developers to update their dependencies to a version that includes the fix and implement input validation to mitigate the risk. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for opensc →

Share this vulnerability

FAQ

OpenSC is an open-source smart card library that provides cryptographic and security functions for interacting with smart cards. It is commonly used in applications that require smart card authentication and secure data storage.

A stack-buffer-overflow is a type of vulnerability where a program writes more data into a buffer than it can hold, causing the excess data to overflow into adjacent memory locations on the stack. This can lead to memory corruption, crashes, or even arbitrary code execution.

An attacker can exploit this vulnerability by crafting a malicious smart card data that triggers the stack-buffer-overflow. By carefully manipulating the length of the ASN.1 tag, the attacker can overwrite adjacent memory locations on the stack, potentially gaining control over the program's execution flow.

The consequences of this vulnerability can vary depending on how the application handles the corrupted data. In the worst case, it can lead to remote code execution, allowing an attacker to execute arbitrary code with the privileges of the application. It can also result in denial-of-service attacks, crashing the application and rendering it unusable.

Yes, a fix for this vulnerability has been implemented in the OpenSC library. Application developers should update their dependencies to a version that includes the fix to mitigate the risk of exploitation.

Related vulnerabilities

Recent vulnerabilities recorded for opensc.

How To Fix

Minimum fixed version

fa378dadb5ee62c5dc1119639ddae797c166a08f

This is the first release that contains the fix.

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback