summaryrefslogtreecommitdiffstats
path: root/0002-Fix-type-check-for-setContentDownload.patch
blob: aa3c7cfad355e7ef13c35a050de3f4d13b7fc638 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From 309da4c0c107c0c32b500db53339fe266bd8b678 Mon Sep 17 00:00:00 2001
From: John Boehr <jbboehr@gmail.com>
Date: Thu, 15 Jun 2017 11:25:52 -0700
Subject: [PATCH 2/3] Fix type check for setContentDownload

* Change exception thrown to InvalidArgumentException
---
 serverresponse.c                                   | 8 +++++++-
 tests/response/setContentDownload_notResource.phpt | 6 +-----
 userland/src/ServerResponse.php                    | 2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/serverresponse.c b/serverresponse.c
index 2e912f7..02853e1 100644
--- a/serverresponse.c
+++ b/serverresponse.c
@@ -648,13 +648,19 @@ PHP_METHOD(ServerResponse, setContentDownload)
     smart_str buf2 = {0};
 
     ZEND_PARSE_PARAMETERS_START(2, 4)
-        Z_PARAM_RESOURCE(zstream)
+        Z_PARAM_ZVAL(zstream)
         Z_PARAM_STR(name)
         Z_PARAM_OPTIONAL
         Z_PARAM_STR(disposition)
         Z_PARAM_ARRAY(params)
     ZEND_PARSE_PARAMETERS_END();
 
+    // Check type of resource parameter
+    if( Z_TYPE_P(zstream) != IS_RESOURCE ) {
+        zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Argument 1 passed to ServerResponse::setContentDownload() must be of the type resource, string given");
+        return;
+    }
+
     // Initialize params
     if( !params || Z_TYPE_P(params) != IS_ARRAY ) {
         params = &_params;
diff --git a/tests/response/setContentDownload_notResource.phpt b/tests/response/setContentDownload_notResource.phpt
index 1e9cb45..0688334 100644
--- a/tests/response/setContentDownload_notResource.phpt
+++ b/tests/response/setContentDownload_notResource.phpt
@@ -14,11 +14,7 @@ json
 $response = new ServerResponse();
 try {
     $response->setContentDownload('not-a-resource', 'disposition');
-} catch( TypeError $e ) {
-    // php 7 (extension)
-    var_dump($e->getMessage());
-} catch( RuntimeException $e ) {
-    // php 5 (userland)
+} catch( InvalidArgumentException $e ) {
     var_dump($e->getMessage());
 }
 --EXPECT--
-- 
2.9.4