GTKWave VCD get_vartoken realloc use-after-free vulnerabilities
A use-after-free flaw in GTKWave's VCD parsing code occurs when a variable name with a range causes a buffer reallocation, leaving a dangling pointer. An attacker could exploit this by crafting a malicious .vcd file that, when opened, may lead to arbitrary code execution.
Originally disclosed on Cisco Talos
Multiple use-after-free vulnerabilities exist in the VCD getvartoken realloc functionality of GTKWave 3.3.115. A specially crafted .vcd file can lead to arbitrary code execution.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code stores a pointer (varsplit) into a buffer (yytext) that is later reallocated, so the pointer becomes dangling and is subsequently used to write and read memory.
Impact
This could lead to arbitrary code execution, though the text notes that exploitation requires careful heap manipulation.
What the attacker needed
Victim opens a malicious .vcd file
The fix
The vulnerability was fixed in version 3.3.118.
How it was found
- Open a malicious .vcd file with GTKWave or one of its conversion tools.
- The parser reads a $var token and calls get_vartoken.
- A long variable name with a range triggers realloc of yytext, freeing the old buffer.
- The varsplit pointer still points into the freed buffer.
- The code writes a null byte to the freed memory and later uses a length derived from the dangling pointer.
- This can cause an out-of-bounds write when copying the variable name.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
GTKWave is a program for viewing electronic signal traces. A use-after-free bug happens when the program keeps using a memory area after it has been freed and possibly moved. Here, a specially made trace file can cause the program to write data to the wrong place in memory, which might let an attacker run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.