php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72975 ldap_escape could produce string larger than 2Gb
Submitted: 2016-08-30 14:03 UTC Modified: 2017-02-13 01:25 UTC
From: nguyenluan dot vnn at gmail dot com Assigned: stas (profile)
Status: Closed Package: LDAP related
PHP Version: 5.6.25 OS:
Private report: No CVE-ID: None
 [2016-08-30 14:03 UTC] nguyenluan dot vnn at gmail dot com
Description:
------------
The ldap_escape function does NOT check for the MAX output string length. It can produce string larger than 2Gb. This string is considered invalid in PHP 5 and could lead to memory corruption when feed to other functions.

Test script:
---------------
<?php
	ini_set('memory_limit', -1);

	$str = str_repeat('a', 0x40000000).'\\\\\\\\'.str_repeat('+', 0x40000000 - 5);
	var_dump(strlen($str));

	$str1 = ldap_escape($str, null, LDAP_ESCAPE_FILTER);
	var_dump(strlen($str1));
?>

Expected result:
----------------
Error, output string length larger than 2Gb

Actual result:
--------------
int(2147483647)
int(-2147483641)  // output string with length > 2Gb


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-02 06:31 UTC] stas@php.net
-Assigned To: +Assigned To: stas
 [2016-09-02 06:31 UTC] stas@php.net
The fix is in security repo as 0f1eb74e92191e817b4198ceda4e8f093699da62 and in https://gist.github.com/39b697c75a0502e091a1191f83029034
please verify
 [2016-09-02 16:06 UTC] nguyenluan dot vnn at gmail dot com
The patch is good.
 [2016-09-13 04:12 UTC] stas@php.net
-Status: Assigned +Status: Closed
 [2016-09-13 04:12 UTC] stas@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2016-09-13 12:36 UTC] nguyenluan dot vnn at gmail dot com
Can you assign a CVE number for this?
 [2016-09-13 16:59 UTC] stas@php.net
I don't think this needs a CVE. Running without memory limit in production and escaping user-suppied 2G string does not look like a common scenario. Same for all other non-memory-limit issues.
 [2016-09-14 14:01 UTC] nguyenluan dot vnn at gmail dot com
But in this bug https://bugs.php.net/bug.php?id=72513, running without memory limit and opening large path name still have CVE number.
 [2017-02-13 01:25 UTC] stas@php.net
-Type: Security +Type: Bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC