Heap-buffer-overflow in mruby
Summary
OSV-2023-881: Heap-buffer-overflow in read_tmpl. Affects mruby versions >= 1e1184f62d4b530061c33341f297c017851d28f7, < 393aaada64a7ec77313ef2516fce1c2052b547c8. Fixed in 393aaada64a7ec77313ef2516fce1c2052b547c8. How to fix ↓
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.
No signup required · Results in about 60 seconds
Background
mruby is an open-source lightweight implementation of the Ruby programming language. It is designed to be embedded in other applications to provide scripting capabilities. The vulnerability in mruby is a heap-buffer-overflow issue that can lead to a crash when reading a template file.
Vulnerability Detail
The vulnerability occurs in the read_tmpl function of mruby. It is triggered by a heap-buffer-overflow when attempting to read data from a template file. This can result in a crash and potentially allow an attacker to execute arbitrary code or cause a denial-of-service. The vulnerability was discovered through the OSS-Fuzz project.
How To Fix
Minimum fixed version
393aaada64a7ec77313ef2516fce1c2052b547c8
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
If updating mruby is not immediately feasible, a possible workaround is to implement input validation and bounds checking when reading template files. This can help mitigate the risk of a heap-buffer-overflow. Here is an example of how to perform input validation in Ruby:
def read_tmpl(file)
# Perform input validation
raise 'Invalid file' unless File.exist?(file)
raise 'Invalid file type' unless File.file?(file)
# Read template file
data = File.read(file)
# Process template data
# ...
end
Conclusion
The heap-buffer-overflow vulnerability in mruby can be resolved by updating to a version that includes the fix. If immediate updating is not possible, implementing input validation and bounds checking can provide a temporary workaround. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for mruby →
FAQ
mruby is a lightweight implementation of the Ruby programming language designed to be embedded in other applications.
The vulnerability occurs when reading a template file, leading to a heap-buffer-overflow.
The vulnerability can result in a crash and potentially allow an attacker to execute arbitrary code or cause a denial-of-service.
To fix the vulnerability, update mruby to a version that includes the fix.
If updating mruby is not immediately feasible, implementing input validation and bounds checking when reading template files can help mitigate the risk.
References
Related vulnerabilities
Recent vulnerabilities recorded for mruby.