VYPR
Unrated severityNVD Advisory· Published Jan 17, 2003· Updated Jun 16, 2026

CVE-2002-1396

CVE-2002-1396

Description

Heap-based buffer overflow in the wordwrap function in PHP after 4.1.2 and before 4.3.0 may allow attackers to cause a denial of service or execute arbitrary code.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

Affected products

6
  • PHP/PHP6 versions
    cpe:2.3:a:php:php:4.1.2:*:*:*:*:*:*:*+ 5 more
    • cpe:2.3:a:php:php:4.1.2:*:*:*:*:*:*:*
    • cpe:2.3:a:php:php:4.2.0:*:*:*:*:*:*:*
    • cpe:2.3:a:php:php:4.2.1:*:*:*:*:*:*:*
    • cpe:2.3:a:php:php:4.2.2:*:*:*:*:*:*:*
    • cpe:2.3:a:php:php:4.2.3:*:*:*:*:*:*:*
    • (no CPE)range: >=4.1.2 <4.3.0

Patches

Vulnerability mechanics

Root cause

"Heap buffer overflow in wordwrap() due to insufficient output buffer allocation when the 'cut' parameter is enabled."

Attack vector

An attacker can trigger the overflow by supplying a crafted string and a `wordwrap()` call with a `width` argument of 20 and a long `break` string (e.g., "CANITBREAKFOO") with the `cut` flag set to 1 [ref_id=1]. The `wordwrap` function writes one byte past the allocated buffer, corrupting heap metadata. This corruption can later cause a segmentation fault inside `malloc()` when PHP attempts to allocate memory for a subsequent operation (e.g., a PostgreSQL query), leading to denial of service or potentially arbitrary code execution [CWE-122].

Affected code

The heap-based buffer overflow resides in the `zif_wordwrap` function in PHP's string handling code. The bug was present in PHP versions after 4.1.2 and before 4.3.0, including 4.2.2, 4.2.3, and 4.3.0RC2/RC3.

What the fix does

The patch is not included in the bundle, but the bug report indicates the overflow was fixed between PHP 4.3.0RC2 and the final 4.3.0 release [ref_id=1]. The fix would correct the buffer size calculation in `zif_wordwrap` so that when the `cut` parameter is enabled, the allocated output buffer is large enough to hold the inserted break string without writing past the end. Without this fix, the function writes one or two bytes beyond the allocated block, corrupting adjacent heap memory.

Preconditions

  • inputThe attacker must be able to supply a string and parameters to PHP's wordwrap() function, typically through a web application that passes user-controlled input to wordwrap().
  • configThe wordwrap() call must use a 'width' of 20, a break string longer than 1 character (e.g., 'CANITBREAKFOO'), and the 'cut' flag set to 1.

Reproduction

```php <?php $x = "ADV:CLAIM YOUR FORTUNE NOW !!MAKE"; $x .= " xxxxxxxxxxHUNDREDS OF THOUSANDSxxxxxxxxxxxx"; $b = "CANITBREAKFOO"; $x = wordwrap($x, 20, $b, 1); $x = wordwrap($x, 20, $b, 1); ?> ``` Running this script on PHP 4.2.2, 4.2.3, or 4.3.0RC2 causes a segmentation fault [ref_id=1].

Generated on Jun 17, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

9

News mentions

0

No linked articles in our index yet.