Cve 2022 31625 Php Vulnerability Due To Uninitialized Array
PHP's pg_query_params() allocated an array of parameter pointers without initialising it, so on an error path the code freed memory using leftover values as pointers. An attacker able to supply invalid parameters to a parameterised query could trigger memory corruption, potentially leading to remote code execution or denial of service.
Published on infosecwriteups.com
In PHP versions 7.4.x below 7.4.30, 8.0.x below 8.0.20, and 8.1.x below 8.1.7, when pdomysql extension with mysqlnd driver, if the third party is allowed to supply host to connect to and the password for the connection, password of excessive length can trigger a buffer overflow in PHP, which can lead to a remote code…
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 write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the parameter pointer array was allocated with safe_emalloc but never zeroed, so the error-handling cleanup freed uninitialised values as if they were valid pointers.
Impact
Supplying invalid parameters to a parameterised query could lead to remote code execution or denial of service, and the write-up notes the flaw could be turned into a use-after-free that may be easier to exploit than a related CVE.
What the attacker needed
Attacker controls query parameters; Postgres extension in use
The fix
The array should be initialised before use, and the text states official fixed versions (PHP 8.1.7, 8.0.20 and 7.4.30) have been released.
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 write-up has not been written yet. The Original tab links to the source.
When a program asks the computer for memory, that memory can still hold old values from earlier use. Here PHP built a list of pointers (memory addresses) but never cleared it, then treated whatever was left there as real addresses and tried to free them. Freeing a made-up address can crash the program or, in the worst case, 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.