PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/web/diff/CVE-2012-0807/function.patch

https://bitbucket.org/deonjo/vulnerablity_crawler
Patch | 420 lines | 330 code | 90 blank | 0 comment | 0 complexity | c1d909bec4c9160a068146e51ba90ea8 MD5 | raw file
  1. commit 73b1968ee30f6d9d2dae497544b910e68e114bfa
  2. Author: Stefan Esser <stefan@nopiracy.de>
  3. Date: Sat Jan 14 09:44:17 2012 +0100
  4. Fixed stack based buffer overflow in transparent cookie encryption (see separate advisory)
  5. diff --git a/Changelog b/Changelog
  6. index 6c18103..8c2a8a4 100644
  7. --- a/Changelog
  8. +++ b/Changelog
  9. @@ -1,257 +1,258 @@
  10. 2012-01-11 - 0.9.33-dev
  11. + - Fixed stack based buffer overflow in transparent cookie encryption (see separate advisory)
  12. - Fixed that disabling HTTP response splitting protection also disabled NUL byte protection in HTTP headers
  13. - Removed crypt() support - because not used for PHP >= 5.3.0 anyway
  14. 2010-07-23 - 0.9.32.1
  15. - Fixed missing header file resulting in compile errors
  16. 2010-07-23 - 0.9.32
  17. - Added support for memory_limit > 2GB
  18. - Fixed missing header file resulting in wrong php_combined_lcg() prototype being used
  19. - Improved random number seed generation more by adding /dev/urandom juice
  20. 2010-03-28 - 0.9.31
  21. - Fix ZTS build of session.c
  22. - Increased session identifier entropy by using /dev/urandom if available
  23. 2010-03-25 - 0.9.30
  24. - Added line ending characters %0a and %0d to the list of dangerous characters handled
  25. by suhosin.server.encode and suhosin.server.strip
  26. - Fixed crash bug with PHP 5.3.x and session module (due to changed session globals struct)
  27. - Added ! protection to PHP session serializer
  28. - Fixed simulation mode now also affects (dis)allowed functions
  29. - Fixed missing return (1); in random number generator replacements
  30. - Fixed random number generator replacement error case behaviour in PHP 5.3.x
  31. - Fixed error case handling in function_exists() PHP 5.3.x
  32. - Merged changes/fixes in import_request_variables()/extract() from upstream PHP
  33. - Fixed suhosin_header_handler to be PHP 5.3.x compatible
  34. - Merge fixes and new features of PHP's file upload code to suhosin
  35. 2009-08-15 - 0.9.29
  36. - Fixing crash bugs with PHP 5.3.0 caused by unexpected NULL in EG(active_symbol_table)
  37. - Added more compatible way to retrieve ext/session globals
  38. - Increased default length and count limit for POST variables (for people not reading docu)
  39. 2009-08-14 - 0.9.28
  40. - Fixed crash bug with PHP 5.2.10 caused by a change in extension load order of ext/session
  41. - Fixed harmless parameter order error in a bogus memset()
  42. - Disable suhosin.session.cryptua by default because of Internet Explorer 8 "features"
  43. - Added suhosin.executor.include.allow_writable_files which can be disabled to disallow
  44. inclusion of files writable by the webserver
  45. 2008-08-23 - 0.9.27
  46. - Fixed typo in replacement rand() / mt_rand() that was hidden by LAZY symbol loading
  47. 2008-08-22 - 0.9.26
  48. - Fixed problem with suhosin.perdir
  49. Thanks to Hosteurope for tracking this down
  50. - Fixed problems with ext/uploadprogress
  51. Reported by: Christian Stocker
  52. - Added suhosin.srand.ignore and suhosin.mt_srand.ignore (default: on)
  53. - Modified rand()/srand() to use the Mersenne Twister algorithm with separate state
  54. - Added better internal seeding of rand() and mt_rand()
  55. 2008-08-06 - 0.9.25
  56. - Fixed PHP 4 compilation problem introduced in 0.9.24
  57. - Fixed PHP 5.3 compilation problem
  58. - Changed PHP default POST handler to PHP's current handler
  59. 2008-05-10 - 0.9.24
  60. - Added support for method-calls to function handling
  61. - This fixes white- and blacklist affecting methods with the same name
  62. 2008-01-14 - 0.9.23
  63. - Fixed suhosin extension now compiles with snapshots of PHP 5.3
  64. - Fixed crypt() behaves like normal again when there is no salt supplied
  65. 2007-12-01 - 0.9.22
  66. - Removed LFS warning message because it crashed on several systems
  67. 2007-11-30 - 0.9.21
  68. - Fixed function_exists() now checks the Suhosin permissions
  69. - Fixed crypt() salt no longer uses Blowfish by default
  70. - Fixed .htaccess/perdir support
  71. - Fixed compilation problem on OS/X
  72. - Added protection against some attacks through _SERVER variables
  73. - Added suhosin.server.strip and suhosin.server.encode
  74. - Added error message that warns about the LFS binary incompatibility
  75. 2007-05-19 - 0.9.20
  76. - Added protection flags against whitespace at variable start
  77. - Added mutex around crypt() to close the PHP crypt()
  78. thread safety vulnerability class
  79. - Improved HTTP Response Splitting Protection
  80. - Changed default maximum array depth to 50 for GPCR
  81. - Fixed possible endless loop in file logging
  82. - Fixed file locking in file logging
  83. 2007-05-01 - 0.9.19
  84. - Fixed typo in HTTP header protection (only during simulation mode)
  85. Reported by: Ilia Alshanetsky
  86. - Fixed wrong \0 termination in cookie decryptor
  87. - Fixed possible crash in SERVER variables protection when SAPI=embedded
  88. Fix provided by: Olivier Blin/Mandriva Linux
  89. - Added possibility to en-/disable INI_PERDIR
  90. Problem reported by: Ilia Alshanetsky
  91. - Added PHP Warning when disabled function is called
  92. - Added examples for new configuration option in suhosin.ini
  93. 2007-03-06 - 0.9.18
  94. - Fixed session double hooking in edge case
  95. - Added additional crash protection for PHP's session module
  96. 2007-03-04 - 0.9.17
  97. - Added a suhosin.ini example configuration
  98. Thanks to Mandriva Linux for supplying us with one
  99. - Added new logging device: file
  100. - Fixed that suhosin.filter.action did not affect POST limits
  101. - Fixed behaviour of request variable limit to be an upper limit
  102. for the other settings instead of being additive limit
  103. - Fixed hard_memory_limit bypass due to casting bug in PHP
  104. Problem was found by: Ilia Alshanetsky
  105. - Fixed some sql prefix/postfix problems
  106. - Added experimental SQL injection heuristic
  107. 2006-12-02 - 0.9.16
  108. - Added suhosin.stealth which controls if suhosin loads in
  109. stealth mode when it is not the only zend_extension
  110. (Required for full compatibility with certain encoders
  111. that consider open source untrusted. e.g. ionCube, Zend)
  112. - Activate suhosin.stealth by default
  113. - Fixed that Suhosin tries handling functions disabled by
  114. disable_function. In v0.9.15 it was impossible to disable
  115. phpinfo() with disable_function.
  116. Problem was found by: Thorsten Schifferdecker
  117. 2006-11-28 - 0.9.15
  118. - Added a transparent protection for open phpinfo() pages by
  119. adding an HTML META ROBOTS tag to the output that forbids
  120. indexing and archiving
  121. 2006-11-22 - 0.9.14
  122. - Drop wrongly decrypted cookies instead of leaving them empty
  123. - Fix another problem with urlencoded cookie names
  124. - Fix compilation problem with PHP4
  125. - Added better regression to the release process to stop
  126. compilation and missing symbol problems
  127. 2006-11-20 - 0.9.13
  128. - More compatible support for ap_php_snprintf() for old PHP
  129. - Changed phpinfo() output to put suhosin logo into a data: URL
  130. for Opera and Gecko based browsers when expose_php=off
  131. 2006-11-14 - 0.9.12
  132. - Adding ap_php_snprintf() when compiling against PHP 4.3.9
  133. - Added suhosin.protectkey to remove cryptkeys from phpinfo() output
  134. - Disabled suhosin.cookie.encrypt in default install
  135. - Fixed static compilation against PHP 5.2.0
  136. 2006-11-06 - 0.9.11
  137. - Fixed input filter for simulation mode
  138. 2006-10-26 - 0.9.10
  139. - Fixed ZTS compile problem in new code
  140. - Fixed PHP4 compile problem in new code
  141. 2006-10-25 - 0.9.9
  142. - Fixed mail() protection that failed to detect some injected headers
  143. - Fixed cookie decryption to not potentially trash apache memory
  144. - Fixed cookie enctyption to handle url encoded names correctly
  145. - Added suhosin.cookie/session.checkraddr
  146. - Added suhosin.cookie.cryptlist
  147. - Added suhosin.cookie.plainlist
  148. - Added suhosin_encrypt_cookie function for JS
  149. - Added suhosin_get_raw_cookies function
  150. - Changed dropped variable error messages
  151. 2006-10-08 - 0.9.8
  152. - Fixed a PHP4 ZTS compile problem
  153. 2006-10-08 - 0.9.7
  154. - Moved input handler hooking to a later place to ensure better compatibility
  155. with 3rd party extensions
  156. - Fixed a problem with overlong mail headers in mail protection
  157. - Fixed a problem with empty log/verification script names
  158. - Fixed a PHP4 compile problem with old gcc/in ZTS mode
  159. - Added mbregex.h from PHP4 to solve compile problems on systesm with broken
  160. header installations
  161. 2006-10-02 - 0.9.6
  162. - Disallow symlink() when open_basedir (activated by default)
  163. - Fix a problem with compilation in Visual Studio
  164. 2006-09-29 - 0.9.5
  165. - Added missing logo file
  166. - Added suhosin.apc_bug_workaround flag to enable compatibility with buggy APC 3.0.12x
  167. 2006-09-29 - 0.9.4
  168. - Added version number and logo to phpinfo() output
  169. - Fixed that all uploaded files are dropped after a single one was disallowed
  170. - Added undocumented suhosin.coredump flag to tell suhosin to dump core instead
  171. of logging S_MEMORY events
  172. - Disable handling of rfc1867 mbstring decoding
  173. 2006-09-24 - 0.9.3
  174. - Added protection against endless recursion for suhosin.log.phpscript
  175. - Added possibility to disable open_basedir and safe_mode for suhosin.log.phpscript
  176. - Added suhosin.executor.include.max_traversal to stop directory traversal includes
  177. 2006-09-19 - 0.9.2
  178. - Fixes broken rfc1867 fileupload hook
  179. - Changed definition of binary to: 0..31, 128..255 except whitespace
  180. - Added suhosin.log.phpscript(.name) directive to log to a PHP script
  181. 2006-09-16 - 0.9.1
  182. - A bunch of changes to compile and work on Windows
  183. 2006-09-09 - BETA
  184. - Added decryption of HTTP_COOKIE
  185. - Fixed a last problem in suhosin_strcasestr() helper function
  186. 2006-09-08 - BETA
  187. - Fixed a problem within suhosin_strcasestr() because it broke
  188. URL checks
  189. 2006-09-07 - BETA
  190. - CVS version of PHP 5.2.0 was changed to support incasesensitive
  191. URLs, support for this in suhosin added
  192. - Fixed a problem when preg_replace() was called with more than
  193. 4 parameters
  194. diff --git a/header.c b/header.c
  195. index 368e085..74d4ad9 100644
  196. --- a/header.c
  197. +++ b/header.c
  198. @@ -40,126 +40,91 @@ static int (*orig_header_handler)(sapi_header_struct *sapi_header, sapi_headers_
  199. char *suhosin_encrypt_single_cookie(char *name, int name_len, char *value, int value_len, char *key TSRMLS_DC)
  200. {
  201. - char buffer[4096];
  202. - char buffer2[4096];
  203. - char *buf = buffer, *buf2 = buffer2, *d, *d_url;
  204. - int l;
  205. -
  206. - if (name_len > sizeof(buffer)-2) {
  207. - buf = estrndup(name, name_len);
  208. - } else {
  209. - memcpy(buf, name, name_len);
  210. - buf[name_len] = 0;
  211. - }
  212. + char *buf, *buf2, *d, *d_url;
  213. + int l;
  214. +
  215. + buf = estrndup(name, name_len);
  216. +
  217. name_len = php_url_decode(buf, name_len);
  218. - normalize_varname(buf);
  219. - name_len = strlen(buf);
  220. + normalize_varname(buf);
  221. + name_len = strlen(buf);
  222. if (SUHOSIN_G(cookie_plainlist)) {
  223. if (zend_hash_exists(SUHOSIN_G(cookie_plainlist), buf, name_len+1)) {
  224. encrypt_return_plain:
  225. - if (buf != buffer) {
  226. - efree(buf);
  227. - }
  228. + efree(buf);
  229. return estrndup(value, value_len);
  230. }
  231. } else if (SUHOSIN_G(cookie_cryptlist)) {
  232. if (!zend_hash_exists(SUHOSIN_G(cookie_cryptlist), buf, name_len+1)) {
  233. goto encrypt_return_plain;
  234. }
  235. }
  236. - if (strlen(value) <= sizeof(buffer2)-2) {
  237. - memcpy(buf2, value, value_len);
  238. - buf2[value_len] = 0;
  239. - } else {
  240. - buf2 = estrndup(value, value_len);
  241. - }
  242. + buf2 = estrndup(value, value_len);
  243. value_len = php_url_decode(buf2, value_len);
  244. d = suhosin_encrypt_string(buf2, value_len, buf, name_len, key TSRMLS_CC);
  245. d_url = php_url_encode(d, strlen(d), &l);
  246. efree(d);
  247. - if (buf != buffer) {
  248. - efree(buf);
  249. - }
  250. - if (buf2 != buffer2) {
  251. - efree(buf2);
  252. - }
  253. + efree(buf);
  254. + efree(buf2);
  255. return d_url;
  256. }
  257. char *suhosin_decrypt_single_cookie(char *name, int name_len, char *value, int value_len, char *key, char **where TSRMLS_DC)
  258. {
  259. - char buffer[4096];
  260. - char buffer2[4096];
  261. int o_name_len = name_len;
  262. - char *buf = buffer, *buf2 = buffer2, *d, *d_url;
  263. + char *buf, *buf2, *d, *d_url;
  264. int l;
  265. - if (name_len > sizeof(buffer)-2) {
  266. - buf = estrndup(name, name_len);
  267. - } else {
  268. - memcpy(buf, name, name_len);
  269. - buf[name_len] = 0;
  270. - }
  271. -
  272. + buf = estrndup(name, name_len);
  273. +
  274. name_len = php_url_decode(buf, name_len);
  275. - normalize_varname(buf);
  276. - name_len = strlen(buf);
  277. + normalize_varname(buf);
  278. + name_len = strlen(buf);
  279. if (SUHOSIN_G(cookie_plainlist)) {
  280. if (zend_hash_exists(SUHOSIN_G(cookie_plainlist), buf, name_len+1)) {
  281. decrypt_return_plain:
  282. - if (buf != buffer) {
  283. - efree(buf);
  284. - }
  285. + efree(buf);
  286. memcpy(*where, name, o_name_len);
  287. *where += o_name_len;
  288. **where = '='; *where +=1;
  289. memcpy(*where, value, value_len);
  290. *where += value_len;
  291. return *where;
  292. }
  293. } else if (SUHOSIN_G(cookie_cryptlist)) {
  294. if (!zend_hash_exists(SUHOSIN_G(cookie_cryptlist), buf, name_len+1)) {
  295. goto decrypt_return_plain;
  296. }
  297. }
  298. - if (strlen(value) <= sizeof(buffer2)-2) {
  299. - memcpy(buf2, value, value_len);
  300. - buf2[value_len] = 0;
  301. - } else {
  302. - buf2 = estrndup(value, value_len);
  303. - }
  304. + buf2 = estrndup(value, value_len);
  305. value_len = php_url_decode(buf2, value_len);
  306. d = suhosin_decrypt_string(buf2, value_len, buf, name_len, key, &l, SUHOSIN_G(cookie_checkraddr) TSRMLS_CC);
  307. if (d == NULL) {
  308. goto skip_cookie;
  309. }
  310. d_url = php_url_encode(d, l, &l);
  311. efree(d);
  312. memcpy(*where, name, o_name_len);
  313. *where += o_name_len;
  314. **where = '=';*where += 1;
  315. memcpy(*where, d_url, l);
  316. *where += l;
  317. efree(d_url);
  318. skip_cookie:
  319. - if (buf != buffer) {
  320. - efree(buf);
  321. - }
  322. - if (buf2 != buffer2) {
  323. - efree(buf2);
  324. - }
  325. + efree(buf);
  326. + efree(buf2);
  327. return *where;
  328. }
  329. /* {{{ suhosin_cookie_decryptor
  330. */