components/php-5_3/php-sapi/patches/350_php_20803998.patch
author Craig Mohrman <craig.mohrman@oracle.com>
Tue, 16 Jun 2015 14:11:47 -0700
changeset 4494 f5b717124172
permissions -rw-r--r--
20192108 problem in UTILITY/PHP 20231115 problem in UTILITY/PHP 20936509 problem in UTILITY/PHP 20804024 problem in UTILITY/PHP 20804061 problem in UTILITY/PHP 20804135 problem in UTILITY/PHP 20804363 problem in UTILITY/PHP 20804424 problem in UTILITY/PHP 20433657 problem in UTILITY/PHP 20803998 problem in UTILITY/PHP 20804391 problem in UTILITY/PHP
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4494
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     1
CVE-2014-9652
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     2
Community BUG:
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     3
https://bugs.php.net/bug.php?id=68735
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     4
Community CODE:
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     5
https://bugs.php.net/patch-display.php?bug=68735&patch=bug68735.patch&revision=1420309079
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     6
Below is the community patch.
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     7
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     8
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
     9
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    10
index 7e0c856..e7b7855 100644
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    11
--- a/ext/fileinfo/libmagic/softmagic.c
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    12
+++ b/ext/fileinfo/libmagic/softmagic.c
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    13
@@ -884,14 +884,17 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    14
 		size_t sz = file_pstring_length_size(m);
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    15
 		char *ptr1 = p->s, *ptr2 = ptr1 + sz;
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    16
 		size_t len = file_pstring_get_length(m, ptr1);
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    17
-		if (len >= sizeof(p->s)) {
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    18
+		sz = sizeof(p->s) - sz; /* maximum length of string */
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    19
+		if (len >= sz) {
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    20
 			/*
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    21
 			 * The size of the pascal string length (sz)
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    22
 			 * is 1, 2, or 4. We need at least 1 byte for NUL
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    23
 			 * termination, but we've already truncated the
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    24
 			 * string by p->s, so we need to deduct sz.
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    25
+			 * Because we can use one of the bytes of the length
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    26
+			 * after we shifted as NUL termination.
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    27
 			 */ 
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    28
-			len = sizeof(p->s) - sz;
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    29
+			len = sz;
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    30
 		}
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    31
 		while (len--)
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    32
 			*ptr1++ = *ptr2++;
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    33
--- /dev/null	Sat Jan  3 19:01:50 2015
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    34
+++ a/ext/fileinfo/tests/bug68735.phpt	Sat Jan  3 18:57:32 2015
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    35
@@ -0,0 +1,16 @@
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    36
+--TEST--
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    37
+Bug #68735 fileinfo out-of-bounds memory access
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    38
+--SKIPIF--
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    39
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    40
+--FILE--
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    41
+<?php
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    42
+	$test_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug68735.jpg";
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    43
+	$f = new finfo;
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    44
+
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    45
+	var_dump($f->file($test_file));
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    46
+
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    47
+?>
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    48
+===DONE===
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    49
+--EXPECTF--
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    50
+string(%d) "JPEG image data, JFIF standard 1.01, comment: "%S""
f5b717124172 20192108 problem in UTILITY/PHP
Craig Mohrman <craig.mohrman@oracle.com>
parents:
diff changeset
    51
+===DONE===